Skip to content
Snippets Groups Projects
Verified Commit 5354b84b authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix _adjacent_lesson to respect None values

parent fa73bb8a
No related branches found
No related tags found
1 merge request!126Resolve "_adjacent_lesson breaks on persons without lessons"
Pipeline #5523 passed
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment