Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
5df9be91
Commit
5df9be91
authored
Jun 12, 2017
by
Skia
🤘
Browse files
Move computing of start of semester to core/utils
Signed-off-by:
Skia
<
skia@libskia.so
>
parent
a96efafc
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/utils.py
View file @
5df9be91
...
...
@@ -27,11 +27,38 @@ import re
# Image utils
from
io
import
BytesIO
from
datetime
import
datetime
,
timezone
,
date
from
PIL
import
Image
,
ExifTags
# from exceptions import IOError
import
PIL
from
django.conf
import
settings
from
django.core.files.base
import
ContentFile
def
get_start_of_semester
(
d
=
date
.
today
()):
"""
This function computes the start date of the semester with respect to the given date (default is today),
and the start date given in settings.SITH_START_DATE.
It takes the nearest past start date.
Exemples: with SITH_START_DATE = (8, 15)
Today -> Start date
2015-03-17 -> 2015-02-15
2015-01-11 -> 2014-08-15
"""
today
=
d
year
=
today
.
year
start
=
date
(
year
,
settings
.
SITH_START_DATE
[
0
],
settings
.
SITH_START_DATE
[
1
])
start2
=
start
.
replace
(
month
=
(
start
.
month
+
6
)
%
12
)
if
start
>
start2
:
start
,
start2
=
start2
,
start
if
today
<
start
:
return
start2
.
replace
(
year
=
year
-
1
)
elif
today
<
start2
:
return
start
else
:
return
start2
def
scale_dimension
(
width
,
height
,
long_edge
):
if
width
>
height
:
ratio
=
long_edge
*
1.
/
width
...
...
subscription/models.py
View file @
5df9be91
...
...
@@ -32,6 +32,7 @@ from django.core.urlresolvers import reverse
from
django.contrib.auth.forms
import
PasswordResetForm
from
core.models
import
User
from
core.utils
import
get_start_of_semester
...
...
@@ -147,18 +148,7 @@ class Subscription(models.Model):
"""
if
duration
<=
2
:
# Sliding subscriptions for 1 or 2 semesters
return
d
today
=
d
year
=
today
.
year
start
=
date
(
year
,
settings
.
SITH_START_DATE
[
0
],
settings
.
SITH_START_DATE
[
1
])
start2
=
start
.
replace
(
month
=
(
start
.
month
+
6
)
%
12
)
if
start
>
start2
:
start
,
start2
=
start2
,
start
if
today
<
start
:
return
start2
.
replace
(
year
=
year
-
1
)
elif
today
<
start2
:
return
start
else
:
return
start2
return
get_start_of_semester
(
d
)
@
staticmethod
def
compute_end
(
duration
,
start
=
None
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment