From 5354b84bcab7d45262a5de40763faf4966182655 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 24 Jan 2021 20:41:00 +0100 Subject: [PATCH] Fix _adjacent_lesson to respect None values --- aleksis/apps/chronos/model_extensions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aleksis/apps/chronos/model_extensions.py b/aleksis/apps/chronos/model_extensions.py index 269ce3fc..fefea7d4 100644 --- a/aleksis/apps/chronos/model_extensions.py +++ b/aleksis/apps/chronos/model_extensions.py @@ -83,7 +83,7 @@ def lesson_periods_as_teacher(self): @Person.method def lessons_on_day(self, day: date): """Get all lessons of this person (either as participant or teacher) on the given day.""" - return LessonPeriod.objects.on_day(day).filter_from_person(self).order_by("period__period") + return LessonPeriod.objects.order_by("period__period").on_day(day).filter_from_person(self) @Person.method @@ -92,6 +92,10 @@ def _adjacent_lesson( ) -> Union["LessonPeriod", None]: """Get next/previous lesson of the person (either as participant or teacher) on the same day.""" daily_lessons = self.lessons_on_day(day) + + if not daily_lessons: + return None + ids = list(daily_lessons.values_list("id", flat=True)) index = ids.index(lesson_period.pk) -- GitLab