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
3a07d8c0
Verified
Commit
3a07d8c0
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add helper methods for getting next/previous lesson of a person on a day
parent
d0d7bb41
No related branches found
No related tags found
1 merge request
!95
Add helper methods for getting next/previous lesson of a person on a day
Pipeline
#4160
failed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/chronos/model_extensions.py
+33
-0
33 additions, 0 deletions
aleksis/apps/chronos/model_extensions.py
with
33 additions
and
0 deletions
aleksis/apps/chronos/model_extensions.py
+
33
−
0
View file @
3a07d8c0
from
datetime
import
date
from
typing
import
Optional
,
Union
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -79,6 +80,38 @@ def lesson_periods_as_teacher(self):
return
LessonPeriod
.
objects
.
filter
(
lesson__teachers
=
self
)
@Person.method
def
daily_lessons
(
self
,
day
:
date
):
"""
Get all lessons of this person on the given day.
"""
return
LessonPeriod
.
objects
.
on_day
(
day
).
filter_from_person
(
self
)
@Person.method
def
next_lesson
(
self
,
lesson_period
:
"
LessonPeriod
"
,
day
:
date
)
->
Union
[
"
LessonPeriod
"
,
None
]:
"""
Get next lesson of the person on the same day.
"""
daily_lessons
=
self
.
daily_lessons
(
day
)
ids
=
list
(
daily_lessons
.
values_list
(
"
id
"
,
flat
=
True
))
index
=
ids
.
index
(
lesson_period
.
pk
)
if
index
+
1
<
len
(
ids
):
return
daily_lessons
[
index
+
1
]
else
:
return
None
@Person.method
def
previous_lesson
(
self
,
lesson_period
:
"
LessonPeriod
"
,
day
:
date
)
->
Union
[
"
LessonPeriod
"
,
None
]:
"""
Get previous lesson of the person on the same day.
"""
daily_lessons
=
self
.
daily_lessons
(
day
)
ids
=
list
(
daily_lessons
.
values_list
(
"
id
"
,
flat
=
True
))
index
=
ids
.
index
(
lesson_period
.
pk
)
if
index
>
0
:
return
daily_lessons
[
index
-
1
]
else
:
return
None
def
for_timetables
(
cls
):
"""
Return all announcements that should be shown in timetable views.
"""
return
cls
.
objects
.
filter
(
show_in_timetables
=
True
)
...
...
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