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
6529fdb0
Commit
6529fdb0
authored
10 months ago
by
permcu
Browse files
Options
Downloads
Patches
Plain Diff
Implement AbsencesBatchCreateMutation (WIP)
parent
4ac7883d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!362
Resolve "Add personal note management dialog in course book"
Pipeline
#183363
failed
10 months ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Stage: docker
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/alsijil/schema/absences.py
+74
-12
74 additions, 12 deletions
aleksis/apps/alsijil/schema/absences.py
with
74 additions
and
12 deletions
aleksis/apps/alsijil/schema/absences.py
+
74
−
12
View file @
6529fdb0
import
graphene
from
datetime
import
datetime
from
aleksis.apps.kolego.models
import
Absence
from
.documentation
import
DocumentationType
from
..models
import
ParticipationStatus
class
LessonsForPersonType
(
graphene
.
ObjectType
):
id
=
graphene
.
ID
()
# noqa
...
...
@@ -16,16 +21,73 @@ class AbsencesBatchCreateMutation(graphene.Mutation):
ok
=
graphene
.
Boolean
()
@classmethod
def
mutate
(
cls
,
root
,
info
,
input
):
# noqa
# Get all lesson events for person (share with query)
# Look up documentations for lesson events
# (share with models.py Documentation get_for_coursebook;
# has lesson event lookup as well & returns real & fake documentations
# => extract & reuse the documentation lookup)
# Create a ParticipationStatus for each documentation
# (OR if no documentation and in past create documentation)
# If there are any LessonEvents without a documentation
# create a Kolego Absence for the whole duration
# Return ok=True if everything went well.
def
mutate
(
cls
,
root
,
info
,
persons
,
start
,
end
,
comment
,
reason
):
# noqa
# TODO: More permission checks needed?
# DocumentationBatchCreateOrUpdateMutation.create_or_update
# at least already checks permissions.
for
person
in
persons
:
# Get all documentations for this person between start & end
# Could be shared with query
event_params
=
{
"
type
"
:
"
PARTICIPANT
"
,
"
obj_id
"
:
PERSON_ID
,
}
events
=
LessonEvent
.
get_single_events
(
datetime
.
combine
(
start
,
datetime
.
min
.
time
()),
datetime
.
combine
(
end
,
datetime
.
max
.
time
()),
None
,
event_params
,
with_reference_object
=
True
,
)
docs
,
dummies
=
Documentation
.
get_documentations_for_events
(
events
)
# till here -> reuse?
return
AbsencesBatchCreateMutation
(
ok
=
BOOL
)
# Create doc for dummies that are already in the past
future
=
false
for
dummy
in
dummies
:
# TODO/MAYBE: This in past logic could be somewhere else OR shared.
# The next 5 lines are shared with DocumentationBatchCreateOrUpdateMutation
# & could be deduplicated
dummy
,
lesson_event_id
,
datetime_start_iso
,
datetime_end_iso
=
_id
.
split
(
"
;
"
)
lesson_event
=
LessonEvent
.
objects
.
get
(
id
=
lesson_event_id
)
start
=
datetime
.
fromisoformat
(
datetime_start_iso
).
astimezone
(
lesson_event
.
timezone
)
if
start
<
datetime
.
now
():
# In the past -> Create a Documentation
docs
.
append
(
DocumentationBatchCreateOrUpdateMutation
.
create_or_update
(
info
,
dummy
)
)
else
:
future
=
true
# Create a ParticipationStatus for each documentation
for
doc
in
docs
:
# TODO: Is ID for enough for person&reason OR should it
# resolve to django object first?
ParticipationStatus
.
objects
.
create
(
person
=
person
,
related_documentation
=
doc
,
absence_reason
=
reason
,
)
# If there are still dummy documentations in the future
# create a Kolego Absence
if
future
:
# TODO: Should probably lookup person&reason as well
# TODO: Are date_start & date_end from CalendarEvent enough
# or more needed?
Absence
.
objects
.
create
(
date_start
=
datetime
.
now
().
date
(),
date_end
=
end
,
reason
=
reason
,
person
=
person
,
comment
=
comment
,
)
# Return ok=True if everything went well.
return
AbsencesBatchCreateMutation
(
ok
=
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