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

Split get_for_coursebook

into get_documentations_for_events
& get_for_coursebook
This makes it reusable for further purposes (absences).
parent e6708d69
No related branches found
No related tags found
1 merge request!360Resolve "Add absence management to course book student dialog"
...@@ -515,44 +515,17 @@ class Documentation(CalendarEvent): ...@@ -515,44 +515,17 @@ class Documentation(CalendarEvent):
# which is not possible via constraint, because amends is not local to Documentation # which is not possible via constraint, because amends is not local to Documentation
@classmethod @classmethod
def get_for_coursebook( def get_documentations_for_events(
cls, cls,
own: bool, events: list,
date_start: datetime, incomplete: Optional[bool] = False,
date_end: datetime, ) -> tuple:
request: HttpRequest, """Get all the documentations for the events.
obj_type: Optional[str] = None, Create dummy documentations if none exist.
obj_id: Optional[str] = None, Returns a tuple with a list of existing documentations and a list dummy documentations.
incomplete: Optional[bool] = False,
) -> list:
"""Get all the documentations for an object and a time frame.
obj_type may be one of TEACHER, GROUP, ROOM, COURSE
""" """
# 1. Find all LessonEvents for all Lessons of this Course in this date range
event_params = {
"own": own,
}
if obj_type is not None and obj_id is not None:
event_params.update(
{
"type": obj_type,
"id": obj_id,
}
)
events = LessonEvent.get_single_events(
date_start,
date_end,
request,
event_params,
with_reference_object=True,
)
# 2. For each lessonEvent → check if there is a documentation
# if so, add the documentation to a list, if not, create a new one
docs = [] docs = []
dummies = []
for event in events: for event in events:
if incomplete and event["STATUS"] == "CANCELLED": if incomplete and event["STATUS"] == "CANCELLED":
continue continue
...@@ -582,7 +555,7 @@ class Documentation(CalendarEvent): ...@@ -582,7 +555,7 @@ class Documentation(CalendarEvent):
else: else:
course, subject = event_reference_obj.course, event_reference_obj.subject course, subject = event_reference_obj.course, event_reference_obj.subject
docs.append( dummies.append(
cls( cls(
pk=f"DUMMY;{event_reference_obj.id};{event['DTSTART'].dt.isoformat()};{event['DTEND'].dt.isoformat()}", pk=f"DUMMY;{event_reference_obj.id};{event['DTSTART'].dt.isoformat()};{event['DTEND'].dt.isoformat()}",
amends=event_reference_obj, amends=event_reference_obj,
...@@ -593,7 +566,47 @@ class Documentation(CalendarEvent): ...@@ -593,7 +566,47 @@ class Documentation(CalendarEvent):
) )
) )
return docs return (docs, dummies)
@classmethod
def get_for_coursebook(
cls,
own: bool,
date_start: datetime,
date_end: datetime,
request: HttpRequest,
obj_type: Optional[str] = None,
obj_id: Optional[str] = None,
incomplete: Optional[bool] = False,
) -> list:
"""Get all the documentations for an object and a time frame.
obj_type may be one of TEACHER, GROUP, ROOM, COURSE
"""
# Find all LessonEvents for all Lessons of this Course in this date range
event_params = {
"own": own,
}
if obj_type is not None and obj_id is not None:
event_params.update(
{
"type": obj_type,
"id": obj_id,
}
)
events = LessonEvent.get_single_events(
date_start,
date_end,
request,
event_params,
with_reference_object=True,
)
# Lookup or create documentations and return them all.
docs, dummies = cls.get_documentations_for_events(events, incomplete)
return docs + dummies
class ParticipationStatus(CalendarEvent): class ParticipationStatus(CalendarEvent):
......
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