From 83eb191f32608aa8be0186a087c23b108e2da42e Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Thu, 2 May 2024 19:09:04 +0200 Subject: [PATCH] Move get_for_coursebook into schema --- aleksis/apps/alsijil/models.py | 40 ------------------------- aleksis/apps/alsijil/schema/__init__.py | 27 +++++++++++++---- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index d72f27a56..69220a5cf 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -568,46 +568,6 @@ class Documentation(CalendarEvent): 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): """A participation or absence record about a single person. diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index 1bab10d51..f9241adb9 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -62,9 +62,6 @@ class Query(graphene.ObjectType): incomplete=False, **kwargs, ): - datetime_start = datetime.combine(date_start, datetime.min.time()) - datetime_end = datetime.combine(date_end, datetime.max.time()) - if ( ( obj_type == "COURSE" @@ -87,10 +84,30 @@ class Query(graphene.ObjectType): ): raise PermissionDenied() - return Documentation.get_for_coursebook( - own, datetime_start, datetime_end, info.context, obj_type, obj_id, incomplete + # 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( + datetime.combine(date_start, datetime.min.time()), + datetime.combine(date_end, datetime.max.time()), + info.context, + event_params, + with_reference_object=True, ) + # Lookup or create documentations and return them all. + docs, dummies = Documentation.get_documentations_for_events(events, incomplete) + return docs + dummies + @staticmethod def resolve_groups_by_person(root, info, person=None): if person: -- GitLab