Skip to content
Snippets Groups Projects
Verified Commit 6341d76d authored by mirabilos's avatar mirabilos
Browse files

Add helper to retrieve next LessonPeriod for same group(s).

Here, “same group(s)” means: the next time the same constellation
of groups has a lesson period together.

Advances: #34
parent 3f6a6994
No related branches found
No related tags found
No related merge requests found
...@@ -187,6 +187,19 @@ class LessonPeriod(SchoolRelated): ...@@ -187,6 +187,19 @@ class LessonPeriod(SchoolRelated):
def get_groups(self) -> models.query.QuerySet: def get_groups(self) -> models.query.QuerySet:
return self.lesson.groups return self.lesson.groups
def next_of_same_groups(self) -> Optional[LessonPeriod]:
res = LessonPeriod.objects
# retrieve all LessonPeriods of this group constellation
for group in self.lesson.groups.all():
res = res.filter(lesson__groups__pk=group.pk)
# sorted by time
res = res.order_by('period__weekday', 'period__period').distinct()
# simple list of their PKs
all = list(res.values_list('pk', flat=True))
# next one after ourselves, wrapping around
next = all[(all.index(self.pk) + 1) % len(all)]
return LessonPeriod.objects.get(pk=next)
def __str__(self) -> str: def __str__(self) -> str:
return '%s, %d., %s, %s' % (self.period.get_weekday_display(), self.period.period, return '%s, %d., %s, %s' % (self.period.get_weekday_display(), self.period.period,
', '.join(list(self.lesson.groups.values_list('short_name', flat=True))), ', '.join(list(self.lesson.groups.values_list('short_name', flat=True))),
......
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