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
32de3953
Verified
Commit
32de3953
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add documentation for LessonPeriodQuerySet methods.
parent
695169cb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
biscuit/apps/chronos/models.py
+33
-0
33 additions, 0 deletions
biscuit/apps/chronos/models.py
with
33 additions
and
0 deletions
biscuit/apps/chronos/models.py
+
33
−
0
View file @
32de3953
...
...
@@ -33,15 +33,21 @@ class LessonPeriodQuerySet(models.QuerySet):
"""
Overrides default QuerySet to add specific methods for lesson data.
"""
def
in_week
(
self
,
wanted_week
:
CalendarWeek
):
"""
Filter for all lessons within a calendar week.
"""
return
self
.
filter
(
lesson__date_start__lte
=
wanted_week
[
0
]
+
timedelta
(
days
=
1
)
*
(
models
.
F
(
'
period__weekday
'
)
-
1
),
lesson__date_end__gte
=
wanted_week
[
0
]
+
timedelta
(
days
=
1
)
*
(
models
.
F
(
'
period__weekday
'
)
-
1
)
).
annotate_week
(
wanted_week
)
def
within_dates
(
self
,
start
:
date
,
end
:
date
):
"""
Filter for all lessons within a date range.
"""
return
self
.
filter
(
lesson__date_start__gte
=
start
,
lesson__date_end__lte
=
end
)
def
on_day
(
self
,
day
:
date
):
"""
Filter for all lessons on a certain day.
"""
week
,
weekday
=
week_weekday_from_date
(
day
)
return
self
.
within_dates
(
day
,
day
).
filter
(
...
...
@@ -49,6 +55,8 @@ class LessonPeriodQuerySet(models.QuerySet):
).
annotate_week
(
week
)
def
at_time
(
self
,
when
:
Optional
[
datetime
]
=
None
):
"""
Filter for the lessons taking place at a certain point in time.
"""
now
=
when
or
datetime
.
now
()
week
,
weekday
=
week_weekday_from_date
(
now
.
date
())
...
...
@@ -61,22 +69,32 @@ class LessonPeriodQuerySet(models.QuerySet):
).
annotate_week
(
week
)
def
filter_participant
(
self
,
person
:
Union
[
Person
,
int
]):
"""
Filter for all lessons a participant (student) attends.
"""
return
self
.
filter
(
Q
(
lesson__groups__members
=
person
)
|
Q
(
lesson__groups__parent_groups__members
=
person
))
def
filter_group
(
self
,
group
:
Union
[
Group
,
int
]):
"""
Filter for all lessons a group (class) regularly attends.
"""
return
self
.
filter
(
Q
(
lesson__groups
=
group
)
|
Q
(
lesson__groups__parent_groups
=
group
))
def
filter_teacher
(
self
,
teacher
:
Union
[
Person
,
int
]):
"""
Filter for all lessons given by a certain teacher.
"""
return
self
.
filter
(
Q
(
substitutions__teachers
=
teacher
,
substitutions__week
=
models
.
F
(
'
_week
'
))
|
Q
(
lesson__teachers
=
teacher
))
def
filter_room
(
self
,
room
:
Union
[
Room
,
int
]):
"""
Filter for all lessons taking part in a certain room.
"""
return
self
.
filter
(
Q
(
substitutions__room
=
room
,
substitutions__week
=
models
.
F
(
'
_week
'
))
|
Q
(
room
=
room
))
def
annotate_week
(
self
,
week
:
Union
[
CalendarWeek
,
int
]):
"""
Annotate all lessons in the QuerySet with the number of the provided calendar week.
"""
if
isinstance
(
week
,
CalendarWeek
):
week_num
=
week
.
week
else
:
...
...
@@ -87,6 +105,13 @@ class LessonPeriodQuerySet(models.QuerySet):
)
def
next
(
self
,
reference
:
LessonPeriod
,
offset
:
Optional
[
int
]
=
1
)
->
LessonPeriod
:
"""
Get another lesson in an ordered set of lessons.
By default, it returns the next lesson in the set. By passing the offset argument,
the n-th next lesson can be selected. By passing a negative number, the n-th
previous lesson can be selected.
"""
index
=
list
(
self
.
values_list
(
'
id
'
,
flat
=
True
)).
index
(
reference
.
id
)
next_index
=
index
+
offset
...
...
@@ -99,6 +124,14 @@ class LessonPeriodQuerySet(models.QuerySet):
return
self
.
annotate_week
(
week
).
all
()[
next_index
]
def
filter_from_query
(
self
,
query_data
:
QueryDict
):
"""
Apply all filters from a GET or POST query.
This method expects a QueryDict, like the GET or POST attribute of a Request
object, that contains one or more of the keys group, teacher or room.
All three fields are filtered, in order.
"""
if
query_data
.
get
(
'
group
'
,
None
):
return
self
.
filter_group
(
int
(
query_data
[
'
group
'
]))
if
query_data
.
get
(
'
teacher
'
,
None
):
...
...
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