Skip to content
Snippets Groups Projects
Commit 3ba1364c authored by permcu's avatar permcu Committed by Julian
Browse files

Refactor get_documentations_for_person

& share between query & mutation.
parent 27186425
No related branches found
No related tags found
1 merge request!360Resolve "Add absence management to course book student dialog"
......@@ -568,6 +568,33 @@ class Documentation(CalendarEvent):
return (docs, dummies)
@classmethod
def get_documentations_for_person(
cls,
person: int,
start: datetime,
end: datetime,
incomplete: Optional[bool] = False,
) -> tuple:
"""Get all the documentations for the person from start to end datetime.
Create dummy documentations if none exist.
Returns a tuple with a list of existing documentations and a list dummy documentations.
"""
event_params = {
"type": "PARTICIPANT",
"obj_id": PERSON_ID,
}
events = LessonEvent.get_single_events(
start,
end,
None,
event_params,
with_reference_object=True,
)
return Documentation.get_documentations_for_events(events, incomplete)
class ParticipationStatus(CalendarEvent):
"""A participation or absence record about a single person.
......
......@@ -159,21 +159,12 @@ class Query(graphene.ObjectType):
"""
lessons_for_person = []
for person in persons:
event_params = {
"type": "PARTICIPANT",
"obj_id": PERSON_ID,
}
events = LessonEvent.get_single_events(
docs, dummies = Documentation.get_documentations_for_person(
person
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)
lessons_for_person.append(
id=person,
lessons=docs + dummies
......
......@@ -28,23 +28,12 @@ class AbsencesBatchCreateMutation(graphene.Mutation):
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(
docs, dummies = Documentation.get_documentations_for_person(
person,
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?
# Create doc for dummies that are already in the past
future = false
for dummy in dummies:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment