From 2aa7a0e911206c833187f8d5de156f4f38574911 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 11 Aug 2024 19:45:52 +0200 Subject: [PATCH] Fix querying of supervisions --- aleksis/apps/chronos/managers.py | 4 ++++ aleksis/apps/chronos/models.py | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/aleksis/apps/chronos/managers.py b/aleksis/apps/chronos/managers.py index 3b9d1073..6b2f4c3c 100644 --- a/aleksis/apps/chronos/managers.py +++ b/aleksis/apps/chronos/managers.py @@ -950,3 +950,7 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): def amending(self) -> "LessonEventQuerySet": """Get all lesson events that are amending other events.""" return self.filter(amends__isnull=False) + + +class SupervisionEventQuerySet(LessonEventQuerySet): + pass diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index f8e5df90..3189999f 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -42,6 +42,7 @@ from aleksis.apps.chronos.managers import ( LessonPeriodQuerySet, LessonSubstitutionManager, LessonSubstitutionQuerySet, + SupervisionEventQuerySet, SupervisionManager, SupervisionQuerySet, SupervisionSubstitutionManager, @@ -1548,9 +1549,15 @@ class LessonEvent(CalendarEvent): @classmethod def get_objects( - cls, request: HttpRequest | None = None, params: dict[str, any] | None = None, **kwargs + cls, + request: HttpRequest | None = None, + params: dict[str, any] | None = None, + no_effect: bool = False, + **kwargs, ) -> Iterable: """Return all objects that should be included in the calendar.""" + if no_effect: + return super().get_objects(request, params, **kwargs) objs = ( super() .get_objects(request, params, **kwargs) @@ -1614,7 +1621,7 @@ class SupervisionEvent(LessonEvent): name = "supervision" verbose_name = _("Supervisions") - objects = RecurrencePolymorphicManager.from_queryset(LessonEventQuerySet)() + objects = RecurrencePolymorphicManager.from_queryset(SupervisionEventQuerySet)() @classmethod def value_title(cls, reference_object: LessonEvent, request: HttpRequest | None = None) -> str: @@ -1639,10 +1646,22 @@ class SupervisionEvent(LessonEvent): cls, request: HttpRequest | None = None, params: dict[str, any] | None = None, **kwargs ) -> Iterable: """Return all objects that should be included in the calendar.""" - objs = super().get_objects(request, params, **kwargs).instance_of(cls) + objs = super().get_objects(request, params, no_effect=True, **kwargs) if params: obj_id = int(params.get("id", 0)) type_ = params.get("type", None) + not_amended = params.get("not_amended", False) + not_amending = params.get("not_amending", False) + amending = params.get("amending", False) + + if not_amended: + objs = objs.not_amended() + + if not_amending: + objs = objs.not_amending() + + if amending: + objs = objs.amending() if type_ and obj_id: if type_ == "TEACHER": -- GitLab