From 650cc709b1392d7fd312a2d25eaecb020bcae571 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sat, 30 Nov 2024 13:25:28 +0100 Subject: [PATCH] Build substitutions table with current changes that are no amends --- aleksis/apps/chronos/managers.py | 9 +++++++++ aleksis/apps/chronos/models.py | 7 +++++++ aleksis/apps/chronos/util/build.py | 18 +++++++++++------- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/aleksis/apps/chronos/managers.py b/aleksis/apps/chronos/managers.py index 9689ef0b..063829ed 100644 --- a/aleksis/apps/chronos/managers.py +++ b/aleksis/apps/chronos/managers.py @@ -212,6 +212,15 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): """Get all lesson events that are amending other events.""" return self.filter(self.amending_q()) + @staticmethod + def current_changes_q() -> Q: + """Get all lesson events that are current changes.""" + return Q(amends__isnull=False) | Q(current_change=True) + + def current_changes(self) -> "LessonEventQuerySet": + """Get all lesson events that are current changes.""" + return self.filter(self.current_changes_q()) + class SupervisionEventQuerySet(LessonEventQuerySet): pass diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index c212dd43..3c8107ca 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -215,6 +215,9 @@ class LessonEvent(CalendarEvent): blank=True, ) + # current_change=True will show this event in substitutions table + current_change = models.BooleanField(default=False, verbose_name=_("Is this a current change?")) + @property def actual_groups(self: LessonEvent) -> QuerySet[Group]: """Get list of the groups of this lesson event.""" @@ -431,6 +434,7 @@ class LessonEvent(CalendarEvent): not_amended = params.get("not_amended", False) not_amending = params.get("not_amending", False) amending = params.get("amending", False) + current_changes = params.get("current_changes", False) own = params.get("own", False) if not_amended: @@ -442,6 +446,9 @@ class LessonEvent(CalendarEvent): if amending: q = q & LessonEventQuerySet.amending_q() + if current_changes: + q = q & LessonEventQuerySet.current_changes_q() + if request and "own" in params: if own: q = q & LessonEventQuerySet.for_person_q(request.user.person) diff --git a/aleksis/apps/chronos/util/build.py b/aleksis/apps/chronos/util/build.py index a84e4800..2a43d0d0 100644 --- a/aleksis/apps/chronos/util/build.py +++ b/aleksis/apps/chronos/util/build.py @@ -12,19 +12,21 @@ def build_substitutions_list(wanted_day: date) -> tuple[list[dict], set[Person], lesson_events = LessonEvent.get_single_events( datetime.combine(wanted_day, time.min), datetime.combine(wanted_day, time.max), - params={"amending": True}, + params={"current_changes": True}, with_reference_object=True, ) for lesson_event in lesson_events: + ref_object = lesson_event["REFERENCE_OBJECT"] affected_teachers.update(lesson_event["REFERENCE_OBJECT"].teachers.all()) - affected_teachers.update(lesson_event["REFERENCE_OBJECT"].amends.teachers.all()) affected_groups.update(lesson_event["REFERENCE_OBJECT"].groups.all()) - affected_groups.update(lesson_event["REFERENCE_OBJECT"].amends.groups.all()) + if ref_object.amends: + affected_teachers.update(ref_object.amends.teachers.all()) + affected_groups.update(ref_object.amends.groups.all()) row = { "type": "substitution", - "sort_a": lesson_event["REFERENCE_OBJECT"].group_names, + "sort_a": ref_object.group_names, "sort_b": str(lesson_event["DTSTART"]), "el": lesson_event, } @@ -34,13 +36,15 @@ def build_substitutions_list(wanted_day: date) -> tuple[list[dict], set[Person], supervision_events = SupervisionEvent.get_single_events( datetime.combine(wanted_day, time.min), datetime.combine(wanted_day, time.max), - params={"amending": True}, + params={"current_changes": True}, with_reference_object=True, ) for supervision_event in supervision_events: - affected_teachers.update(supervision_event["REFERENCE_OBJECT"].teachers.all()) - affected_teachers.update(supervision_event["REFERENCE_OBJECT"].amends.teachers.all()) + ref_object = supervision_event["REFERENCE_OBJECT"] + affected_teachers.update(ref_object.teachers.all()) + if ref_object.amends: + affected_teachers.update(ref_object.amends.teachers.all()) row = { "type": "supervision_substitution", -- GitLab