From 037639b94d29c1be714e921beb0750298a175f90 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Thu, 29 Feb 2024 18:40:59 +0100 Subject: [PATCH] Remove real_amends as its longer necessary (amends is fixed!) --- aleksis/apps/chronos/models.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index 5bf42890..f803c909 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -1375,7 +1375,7 @@ class LessonEvent(CalendarEvent): @property def actual_groups(self: LessonEvent): - return self.groups.all() if self.amends else self.real_amends.groups.all() + return self.amends.groups.all() if self.amends else self.groups.all() @property def all_members(self: LessonEvent) -> list[Person]: @@ -1385,7 +1385,7 @@ class LessonEvent(CalendarEvent): def all_teachers(self: LessonEvent) -> list[Person]: all_teachers = list(self.teachers.all()) if self.amends: - all_teachers += list(self.real_amends.teachers.all()) + all_teachers += list(self.amends.teachers.all()) return all_teachers @property @@ -1403,7 +1403,7 @@ class LessonEvent(CalendarEvent): @property def room_names_with_amends(self: LessonEvent) -> str: my_room_names = self.room_names - amended_room_names = self.real_amends.room_names if self.amends else "" + amended_room_names = self.amends.room_names if self.amends else "" if my_room_names and amended_room_names: return _("{} (instead of {})").format(my_room_names, amended_room_names) @@ -1414,7 +1414,7 @@ class LessonEvent(CalendarEvent): @property def teacher_names_with_amends(self: LessonEvent) -> str: my_teacher_names = self.teacher_names - amended_teacher_names = self.real_amends.teacher_names if self.amends else "" + amended_teacher_names = self.amends.teacher_names if self.amends else "" if my_teacher_names and amended_teacher_names: return _("{} (instead of {})").format(my_teacher_names, amended_teacher_names) @@ -1425,7 +1425,7 @@ class LessonEvent(CalendarEvent): @property def subject_name_with_amends(self: LessonEvent) -> str: my_subject = self.subject.name - amended_subject = self.real_amends.subject.name if self.amends else "" + amended_subject = self.amends.subject.name if self.amends else "" if my_subject and amended_subject: return _("{} (instead of {})").format(my_subject, amended_subject) @@ -1433,13 +1433,6 @@ class LessonEvent(CalendarEvent): return amended_subject return my_subject - @property - def real_amends(self: LessonEvent) -> LessonEvent: - # FIXME THIS IS AWFUL SLOW - if self.amends: - return LessonEvent.objects.get(pk=self.amends.pk) - return self - @classmethod def value_title(cls, reference_object: LessonEvent, request) -> str: """Get the title of the event.""" @@ -1468,8 +1461,8 @@ class LessonEvent(CalendarEvent): return "#eeeeee" if reference_object.subject: return reference_object.subject.colour_bg - if reference_object.amends and reference_object.real_amends.subject: - return reference_object.real_amends.subject.colour_bg + if reference_object.amends and reference_object.amends.subject: + return reference_object.amends.subject.colour_bg return super().value_color(reference_object, request) @classmethod @@ -1493,11 +1486,12 @@ class LessonEvent(CalendarEvent): @classmethod def value_meta(cls, reference_object: LessonEvent, request) -> str: """Get the meta of the event.""" - real_amends = reference_object.real_amends return { "amended": bool(reference_object.amends), - "amends": cls.value_meta(real_amends, request) if reference_object.amends else None, + "amends": cls.value_meta(reference_object.amends, request) + if reference_object.amends + else None, "teachers": [ { "id": t.pk, -- GitLab