Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Chronos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Chronos
Commits
731abe3d
Verified
Commit
731abe3d
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Use out-sourced calendarweek library
parent
80d8f2da
No related branches found
No related tags found
1 merge request
!31
Biscuit merge. Closes #53.
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/chronos/models.py
+5
-20
5 additions, 20 deletions
aleksis/apps/chronos/models.py
aleksis/apps/chronos/util.py
+3
-93
3 additions, 93 deletions
aleksis/apps/chronos/util.py
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
with
9 additions
and
113 deletions
aleksis/apps/chronos/models.py
+
5
−
20
View file @
731abe3d
...
...
@@ -10,10 +10,12 @@ from django.db.models import F, Q
from
django.http.request
import
QueryDict
from
django.utils.translation
import
ugettext_lazy
as
_
from
calendarweek.django
import
CalendarWeek
,
i18n_day_names_lazy
,
i18n_day_abbrs_lazy
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.models
import
Group
,
Person
from
.util
import
CalendarWeek
,
week_weekday_from_date
from
.util
import
week_weekday_from_date
class
LessonPeriodManager
(
models
.
Manager
):
...
...
@@ -203,25 +205,8 @@ class LessonSubstitutionQuerySet(LessonDataQuerySet):
class
TimePeriod
(
models
.
Model
):
WEEKDAY_CHOICES
=
[
(
0
,
_
(
"
Sunday
"
)),
(
1
,
_
(
"
Monday
"
)),
(
2
,
_
(
"
Tuesday
"
)),
(
3
,
_
(
"
Wednesday
"
)),
(
4
,
_
(
"
Thursday
"
)),
(
5
,
_
(
"
Friday
"
)),
(
6
,
_
(
"
Saturday
"
)),
]
WEEKDAY_CHOICES_SHORT
=
[
(
0
,
_
(
"
Sun
"
)),
(
1
,
_
(
"
Mon
"
)),
(
2
,
_
(
"
Tue
"
)),
(
3
,
_
(
"
Wed
"
)),
(
4
,
_
(
"
Thu
"
)),
(
5
,
_
(
"
Fri
"
)),
(
6
,
_
(
"
Sat
"
)),
]
WEEKDAY_CHOICES
=
i18n_day_names_lazy
()
WEEKDAY_CHOICES_SHORT
=
i18n_day_abbrs_lazy
()
weekday
=
models
.
PositiveSmallIntegerField
(
verbose_name
=
_
(
"
Week day
"
),
choices
=
WEEKDAY_CHOICES
)
period
=
models
.
PositiveSmallIntegerField
(
verbose_name
=
_
(
"
Number of period
"
))
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/util.py
+
3
−
93
View file @
731abe3d
from
__future__
import
annotations
from
datetime
import
date
from
typing
import
Tuple
,
List
from
dataclasses
import
dataclass
from
datetime
import
date
,
datetime
,
timedelta
from
typing
import
Optional
,
Sequence
,
Tuple
,
Union
,
List
from
django.apps
import
apps
from
django.db
import
models
from
django.utils.translation
import
ugettext
as
_
@dataclass
class
CalendarWeek
:
"""
A calendar week defined by year and ISO week number.
"""
year
:
Optional
[
int
]
=
None
week
:
Optional
[
int
]
=
None
@classmethod
def
from_date
(
cls
,
when
:
date
):
"""
Get the calendar week by a date object (the week this date is in).
"""
week
=
int
(
when
.
strftime
(
"
%V
"
))
year
=
when
.
year
+
1
if
when
.
month
==
12
and
week
==
1
else
when
.
year
return
cls
(
year
=
year
,
week
=
week
)
@classmethod
def
current_week
(
cls
)
->
int
:
"""
Get the current week number.
"""
return
cls
().
week
@classmethod
def
weeks_within
(
cls
,
start
:
date
,
end
:
date
)
->
Sequence
[
CalendarWeek
]:
"""
Get all calendar weeks within a date range.
"""
if
start
>
end
:
raise
ValueError
(
"
End date must be after start date.
"
)
current
=
start
weeks
=
[]
while
current
<
end
:
weeks
.
append
(
cls
.
from_date
(
current
))
current
+=
timedelta
(
days
=
7
)
return
weeks
def
__post_init__
(
self
)
->
None
:
today
=
date
.
today
()
if
not
self
.
year
:
self
.
year
=
today
.
year
if
not
self
.
week
:
self
.
week
=
int
(
today
.
strftime
(
"
%V
"
))
def
__str__
(
self
)
->
str
:
return
"
%s %d (%s %s %s)
"
%
(
_
(
"
Calendar Week
"
),
self
.
week
,
self
[
0
],
_
(
"
to
"
),
self
[
-
1
],)
def
__len__
(
self
)
->
int
:
return
7
def
__getitem__
(
self
,
n
:
int
)
->
date
:
if
n
<
-
7
or
n
>
6
:
raise
IndexError
(
"
Week day %d is out of range.
"
%
n
)
if
n
<
0
:
n
+=
7
return
datetime
.
strptime
(
"
%d-%d-%d
"
%
(
self
.
year
,
self
.
week
,
n
+
1
),
"
%G-%V-%u
"
).
date
()
def
__contains__
(
self
,
day
:
date
)
->
bool
:
return
self
.
__class__
.
form_date
(
day
)
==
self
def
__eq__
(
self
,
other
:
CalendarWeek
)
->
bool
:
return
self
.
year
==
other
.
year
and
self
.
week
==
other
.
week
def
__lt__
(
self
,
other
:
CalendarWeek
)
->
bool
:
return
self
[
0
]
<
other
[
0
]
def
__gt__
(
self
,
other
:
CalendarWeek
)
->
bool
:
return
self
[
0
]
>
other
[
0
]
def
__le__
(
self
,
other
:
CalendarWeek
)
->
bool
:
return
self
[
0
]
<=
other
[
0
]
def
__gr__
(
self
,
other
:
CalendarWeek
)
->
bool
:
return
self
[
0
]
>=
other
[
0
]
def
__add__
(
self
,
weeks
:
int
)
->
CalendarWeek
:
return
self
.
__class__
.
from_date
(
self
[
0
]
+
timedelta
(
days
=
weeks
*
7
))
def
__sub__
(
self
,
weeks
:
int
)
->
CalendarWeek
:
return
self
.
__class__
.
from_date
(
self
[
0
]
-
timedelta
(
days
=
weeks
*
7
))
from
calendarweek
import
CalendarWeek
def
week_weekday_from_date
(
when
:
date
)
->
Tuple
[
CalendarWeek
,
int
]:
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
0
View file @
731abe3d
...
...
@@ -20,6 +20,7 @@ classifiers = [
[tool.poetry.dependencies]
python
=
"^3.7"
calendarweek
=
"^0.1"
AlekSIS
=
{
path
=
"../../.."
}
[build-system]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment