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
cbe2050b
Verified
Commit
cbe2050b
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Optimize model extensions
parent
940687dc
No related branches found
No related tags found
1 merge request
!90
Performance optimizations
Pipeline
#3684
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/alsijil/model_extensions.py
+5
-4
5 additions, 4 deletions
aleksis/apps/alsijil/model_extensions.py
aleksis/apps/alsijil/models.py
+7
-0
7 additions, 0 deletions
aleksis/apps/alsijil/models.py
with
12 additions
and
4 deletions
aleksis/apps/alsijil/model_extensions.py
+
5
−
4
View file @
cbe2050b
from
datetime
import
date
from
typing
import
Dict
,
Optional
,
Union
from
typing
import
Dict
,
Optional
,
Union
,
Iterator
from
django.db.models
import
Exists
,
OuterRef
,
QuerySet
from
django.utils.translation
import
gettext
as
_
...
...
@@ -186,11 +186,12 @@ def get_or_create_lesson_documentation(
@LessonPeriod.method
def
get_absences
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
QuerySet
:
def
get_absences
(
self
,
week
:
Optional
[
CalendarWeek
]
=
None
)
->
Iterator
:
"""
Get all personal notes of absent persons for this lesson.
"""
if
not
week
:
week
=
self
.
week
return
self
.
personal_notes
.
filter
(
week
=
week
.
week
,
year
=
week
.
year
,
absent
=
True
)
return
filter
(
lambda
p
:
p
.
week
==
week
.
week
and
p
.
year
==
week
.
year
and
p
.
absent
,
self
.
personal_notes
.
all
())
@LessonPeriod.method
...
...
@@ -230,7 +231,7 @@ def get_extra_marks(
week
=
self
.
week
stats
=
{}
for
extra_mark
in
ExtraMark
.
objects
.
all
()
:
for
extra_mark
in
ExtraMark
.
all
:
qs
=
self
.
personal_notes
.
filter
(
week
=
week
.
week
,
year
=
week
.
year
,
extra_marks
=
extra_mark
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/alsijil/models.py
+
7
−
0
View file @
cbe2050b
from
cache_memoize
import
cache_memoize
from
django.db
import
models
from
django.utils.decorators
import
classproperty
from
django.utils.formats
import
date_format
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -207,6 +209,11 @@ class ExtraMark(ExtensibleModel):
def
count_label
(
self
):
return
f
"
{
self
.
short_name
}
_count
"
@classproperty
@cache_memoize
(
3600
)
def
all
(
cls
):
return
cls
.
objects
.
all
()
class
Meta
:
ordering
=
[
"
short_name
"
]
verbose_name
=
_
(
"
Extra mark
"
)
...
...
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