Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Alsijil
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-Alsijil
Commits
8210047e
Verified
Commit
8210047e
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add class register model extensions to Event and ExtraLesson models
parent
f9991cec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!120
Resolve "Support events and extra lessons in class register"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/alsijil/model_extensions.py
+59
-1
59 additions, 1 deletion
aleksis/apps/alsijil/model_extensions.py
with
59 additions
and
1 deletion
aleksis/apps/alsijil/model_extensions.py
+
59
−
1
View file @
8210047e
...
...
@@ -10,7 +10,7 @@ from calendarweek import CalendarWeek
from
django_global_request.middleware
import
get_request
from
reversion
import
set_user
from
aleksis.apps.chronos.models
import
LessonPeriod
from
aleksis.apps.chronos.models
import
Event
,
ExtraLesson
,
LessonPeriod
from
aleksis.core.models
import
Group
,
Person
from
.models
import
ExcuseType
,
ExtraMark
,
LessonDocumentation
,
PersonalNote
...
...
@@ -184,6 +184,19 @@ def get_lesson_documentation(
return
None
def
get_lesson_documentation_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
Union
[
LessonDocumentation
,
None
]:
"""
Get lesson documentation object for this event/extra lesson.
"""
if
self
.
documentations
.
exists
():
return
self
.
documentations
.
all
()[
0
]
return
None
Event
.
method
(
get_lesson_documentation_simple
,
"
get_lesson_documentation
"
)
ExtraLesson
.
method
(
get_lesson_documentation_simple
,
"
get_lesson_documentation
"
)
@LessonPeriod.method
def
get_or_create_lesson_documentation
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
...
...
@@ -197,6 +210,20 @@ def get_or_create_lesson_documentation(
return
lesson_documentation
def
get_or_create_lesson_documentation_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
LessonDocumentation
:
"""
Get or create lesson documentation object for this event/extra lesson.
"""
lesson_documentation
,
created
=
LessonDocumentation
.
objects
.
get_or_create
(
**
{
"
event
"
if
isinstance
(
self
,
Event
)
else
"
extra_lesson
"
:
self
}
)
return
lesson_documentation
Event
.
method
(
get_or_create_lesson_documentation_simple
,
"
get_or_create_lesson_documentation
"
)
ExtraLesson
.
method
(
get_or_create_lesson_documentation_simple
,
"
get_or_create_lesson_documentation
"
)
@LessonPeriod.method
def
get_absences
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
Iterator
:
"""
Get all personal notes of absent persons for this lesson.
"""
...
...
@@ -209,6 +236,11 @@ def get_absences(self, week: Optional[CalendarWeek] = None) -> Iterator:
)
def
get_absences_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
Iterator
:
"""
Get all personal notes of absent persons for this event/extra lesson.
"""
return
self
.
personal_notes
.
all
()
@LessonPeriod.method
def
get_excused_absences
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
"""
Get all personal notes of excused absent persons for this lesson.
"""
...
...
@@ -217,6 +249,11 @@ def get_excused_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
return
self
.
personal_notes
.
filter
(
week
=
week
.
week
,
year
=
week
.
year
,
absent
=
True
,
excused
=
True
)
def
get_excused_absences_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
"""
Get all personal notes of excused absent persons for this event/extra lesson.
"""
return
self
.
personal_notes
.
filter
(
absent
=
True
,
excused
=
True
)
@LessonPeriod.method
def
get_unexcused_absences
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
"""
Get all personal notes of unexcused absent persons for this lesson.
"""
...
...
@@ -225,6 +262,11 @@ def get_unexcused_absences(self, week: Optional[CalendarWeek] = None) -> QuerySe
return
self
.
personal_notes
.
filter
(
week
=
week
.
week
,
year
=
week
.
year
,
absent
=
True
,
excused
=
False
)
def
get_unexcused_absences_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
"""
Get all personal notes of unexcused absent persons for this event/extra lesson.
"""
return
self
.
personal_notes
.
filter
(
absent
=
True
,
excused
=
False
)
@LessonPeriod.method
def
get_tardinesses
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
"""
Get all personal notes of late persons for this lesson.
"""
...
...
@@ -233,6 +275,11 @@ def get_tardinesses(self, week: Optional[CalendarWeek] = None) -> QuerySet:
return
self
.
personal_notes
.
filter
(
week
=
week
.
week
,
year
=
week
.
year
,
late__gt
=
0
)
def
get_tardinesses_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
"""
Get all personal notes of late persons for this event/extra lesson.
"""
return
self
.
personal_notes
.
filter
(
late__gt
=
0
)
@LessonPeriod.method
def
get_extra_marks
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
Dict
[
ExtraMark
,
QuerySet
]:
"""
Get all statistics on extra marks for this lesson.
"""
...
...
@@ -248,6 +295,17 @@ def get_extra_marks(self, week: Optional[CalendarWeek] = None) -> Dict[ExtraMark
return
stats
def
get_extra_marks_simple
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
Dict
[
ExtraMark
,
QuerySet
]:
"""
Get all statistics on extra marks for this event/extra lesson.
"""
stats
=
{}
for
extra_mark
in
ExtraMark
.
objects
.
all
():
qs
=
self
.
personal_notes
.
filter
(
extra_marks
=
extra_mark
)
if
qs
:
stats
[
extra_mark
]
=
qs
return
stats
@Group.class_method
def
get_groups_with_lessons
(
cls
:
Group
):
"""
Get all groups which have related lessons or child groups with related lessons.
"""
...
...
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