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
29ba4088
Verified
Commit
29ba4088
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Move some APIs to model extensions on chronos models.
parent
183c2c1a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
biscuit/apps/alsijil/model_extensions.py
+47
-0
47 additions, 0 deletions
biscuit/apps/alsijil/model_extensions.py
biscuit/apps/alsijil/views.py
+1
-20
1 addition, 20 deletions
biscuit/apps/alsijil/views.py
with
48 additions
and
20 deletions
biscuit/apps/alsijil/model_extensions.py
0 → 100644
+
47
−
0
View file @
29ba4088
from
django.db.models
import
Exists
,
OuterRef
from
biscuit.apps.chronos.models
import
Lesson
,
LessonPeriod
from
biscuit.apps.chronos.util
import
CalendarWeek
from
biscuit.core.models
import
Group
,
Person
from
.models
import
PersonalNote
@Person.property
def
lessons_as_participant
(
self
):
return
Lesson
.
objects
.
filter
(
groups__members
=
self
)
@Person.property
def
lesson_periods_as_participant
(
self
):
return
LessonPeriod
.
objects
.
filter
(
lesson__groups__members
=
self
)
@Person.property
def
lesson_periods_as_teacher
(
self
):
return
LessonPeriod
.
objects
.
filter
(
lesson__teachers
=
self
)
@LessonPeriod.method
def
personal_notes
(
self
,
wanted_week
:
CalendarWeek
):
# Find all persons in the associated groups that do not yet have a personal note for this lesson
missing_persons
=
Person
.
objects
.
annotate
(
no_personal_notes
=~
Exists
(
PersonalNote
.
objects
.
filter
(
week
=
wanted_week
.
week
,
lesson_period
=
self
,
person__pk
=
OuterRef
(
'
pk
'
)
))
).
filter
(
member_of__in
=
Group
.
objects
.
filter
(
pk__in
=
self
.
lesson
.
groups
.
all
()),
is_active
=
True
,
no_personal_notes
=
True
)
# Create all missing personal notes
PersonalNote
.
objects
.
bulk_create
([
PersonalNote
(
person
=
person
,
lesson_period
=
self
,
week
=
wanted_week
.
week
)
for
person
in
missing_persons
])
return
PersonalNote
.
objects
.
select_related
(
'
person
'
).
filter
(
lesson_period
=
self
,
week
=
wanted_week
.
week
)
This diff is collapsed.
Click to expand it.
biscuit/apps/alsijil/views.py
+
1
−
20
View file @
29ba4088
...
...
@@ -48,28 +48,9 @@ def lesson(request: HttpRequest, year: Optional[int] = None, week: Optional[int]
lesson_documentation_form
=
LessonDocumentationForm
(
request
.
POST
or
None
,
instance
=
lesson_documentation
,
prefix
=
'
leson_documentation
'
)
# Find all persons in the associated groups that do not yet have a personal note for this lesson
missing_persons
=
Person
.
objects
.
annotate
(
no_personal_notes
=~
Exists
(
PersonalNote
.
objects
.
filter
(
week
=
wanted_week
.
week
,
lesson_period
=
lesson_period
,
person__pk
=
OuterRef
(
'
pk
'
)
))
).
filter
(
member_of__in
=
Group
.
objects
.
filter
(
pk__in
=
lesson_period
.
lesson
.
groups
.
all
()),
is_active
=
True
,
no_personal_notes
=
True
)
# Create all missing personal notes
PersonalNote
.
objects
.
bulk_create
([
PersonalNote
(
person
=
person
,
lesson_period
=
lesson_period
,
week
=
wanted_week
.
week
)
for
person
in
missing_persons
# FIXME Respect year as well
])
# Create a formset that holds all personal notes for all persons in this lesson
persons_qs
=
PersonalNote
.
objects
.
select_related
(
'
person
'
).
filter
(
lesson_period
=
lesson_period
,
week
=
wanted_week
.
week
)
# FIXME Respect year as well
persons_qs
=
lesson_period
.
personal_notes
(
wanted_week
)
personal_note_formset
=
PersonalNoteFormSet
(
request
.
POST
or
None
,
queryset
=
persons_qs
,
prefix
=
'
personal_notes
'
)
...
...
This diff is collapsed.
Click to expand it.
Nik | Klampfradler
@nik
mentioned in commit
ba7036cf
·
5 years ago
mentioned in commit
ba7036cf
mentioned in commit ba7036cf0f695965c631b94c5dfd781e1679f95b
Toggle commit list
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