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
257c5d3c
Verified
Commit
257c5d3c
authored
11 months ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Improve creation of participation statuses
parent
68a59686
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!360
Resolve "Add absence management to course book student dialog"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/alsijil/models.py
+41
-26
41 additions, 26 deletions
aleksis/apps/alsijil/models.py
aleksis/apps/alsijil/schema/documentation.py
+12
-3
12 additions, 3 deletions
aleksis/apps/alsijil/schema/documentation.py
with
53 additions
and
29 deletions
aleksis/apps/alsijil/models.py
+
41
−
26
View file @
257c5d3c
...
...
@@ -42,7 +42,7 @@ from aleksis.apps.kolego.models import Absence as KolegoAbsence
from
aleksis.apps.kolego.models
import
AbsenceReason
from
aleksis.core.data_checks
import
field_validation_data_check_factory
from
aleksis.core.mixins
import
ExtensibleModel
,
GlobalPermissionModel
from
aleksis.core.models
import
CalendarEvent
,
Group
,
SchoolTerm
from
aleksis.core.models
import
CalendarEvent
,
Group
,
Person
,
SchoolTerm
from
aleksis.core.util.core_helpers
import
get_site_preferences
from
aleksis.core.util.model_helpers
import
ICONS
...
...
@@ -660,29 +660,12 @@ class Documentation(CalendarEvent):
amends
=
lesson_event
,
course
=
course
,
subject
=
subject
,
topic
=
""
,
homework
=
""
,
group_note
=
""
,
)
obj
.
teachers
.
set
(
teachers
.
all
())
obj
.
save
()
# Create Participation Statuses
# Cannot use djangos bulk_create method, as then the save method of the
# superclass wouldn't be called
for
member
in
lesson_event
.
all_members
:
# TODO: Check for preexisting absences in kolego
# TODO: maybe only create if the lesson start is in the past
status
=
ParticipationStatus
.
objects
.
create
(
person
=
member
,
related_documentation
=
obj
,
datetime_start
=
datetime_start
,
datetime_end
=
datetime_end
,
timezone
=
lesson_event
.
timezone
,
)
status
.
groups_of_person
.
set
(
member
.
member_of
.
all
())
status
.
save
()
obj
.
touch
()
return
obj
...
...
@@ -692,15 +675,47 @@ class Documentation(CalendarEvent):
return
cls
.
create_from_lesson_event
(
user
,
*
cls
.
parse_dummy
(
_id
),
)
return
cls
.
objects
.
get
(
id
=
_id
)
),
True
return
cls
.
objects
.
get
(
id
=
_id
),
False
def
build_participation_status
(
self
,
person
:
Person
)
->
"
ParticipationStatus
"
:
"""
Build participation status object for this documentation and a person.
"""
return
ParticipationStatus
(
person
=
person
,
related_documentation
=
self
,
datetime_start
=
self
.
datetime_start
,
datetime_end
=
self
.
datetime_end
,
# Set timezone directly as save of ParticipationStatus won't be called in bulk_create
timezone
=
self
.
timezone
,
)
def
touch
(
self
):
# TODO: check if participation statuses etc. are created correctly.
# might require some extra work, as the object may have been created
# recently, so checking again would be overkill.
pass
# TODO: Check for preexisting absences in kolego
# TODO: maybe only create if the lesson start is in the past
if
not
self
.
amends
:
# There is no source to update from
return
lesson_event
:
LessonEvent
=
self
.
amends
all_members
=
lesson_event
.
all_members
existing_participations
=
ParticipationStatus
.
objects
.
filter
(
person__in
=
all_members
,
related_documentation
=
self
)
new_persons
=
Person
.
objects
.
filter
(
Q
(
pk__in
=
[
p
.
pk
for
p
in
all_members
])
&
~
Q
(
pk__in
=
existing_participations
.
values_list
(
"
person
"
,
flat
=
True
))
).
prefetch_related
(
"
member_of
"
)
new_participations
=
[]
for
person
in
new_persons
:
participation_status
=
self
.
build_participation_status
(
person
)
participation_status
.
save
()
participation_status
.
groups_of_person
.
set
(
person
.
member_of
.
all
())
new_participations
.
append
(
participation_status
)
return
new_participations
class
ParticipationStatus
(
CalendarEvent
):
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/alsijil/schema/documentation.py
+
12
−
3
View file @
257c5d3c
...
...
@@ -109,7 +109,7 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
# Sadly, we can't use the update_or_create method since create_defaults
# is only introduced in Django 5.0
obj
=
Documentation
.
get_or_create_by_id
(
_id
,
info
.
context
.
user
)
obj
,
__
=
Documentation
.
get_or_create_by_id
(
_id
,
info
.
context
.
user
)
if
not
info
.
context
.
user
.
has_perm
(
"
alsijil.edit_documentation_rule
"
,
obj
):
raise
PermissionDenied
()
...
...
@@ -146,6 +146,15 @@ class TouchDocumentationMutation(graphene.Mutation):
documentation
=
graphene
.
Field
(
DocumentationType
)
def
mutate
(
root
,
info
,
documentation_id
):
documentation
=
Documentation
.
get_or_create_by_id
(
documentation_id
,
info
.
context
.
user
)
documentation
.
touch
()
documentation
,
created
=
Documentation
.
get_or_create_by_id
(
documentation_id
,
info
.
context
.
user
)
if
not
info
.
context
.
user
.
has_perm
(
"
alsijil.edit_participation_status_for_documentation_rule
"
,
documentation
):
raise
PermissionDenied
()
# FIXME Should not be effective in past
if
not
created
:
documentation
.
touch
()
return
TouchDocumentationMutation
(
documentation
=
documentation
)
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