Commit 78dd5441 authored by mirabilos's avatar mirabilos Committed by mirabilos

WIP commit

parent 0d9d518d
......@@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _
from biscuit.core.mixins import SchoolRelated
from .util import CalendarWeek
from .util import CalendarWeek, week_weekday_to_date
class TimePeriod(SchoolRelated):
......@@ -196,16 +196,30 @@ class LessonPeriod(SchoolRelated):
if same_subject:
res = res.filter(lesson__subject=self.lesson.subject)
# limit to same Stundenplan (XXX TODO)
res = res.filter(lesson__date_start=y.lesson.date_start)
r1 = res.filter(lesson__date_start=y.lesson.date_start)
# sorted by time
res = res.order_by('period__weekday', 'period__period').distinct()
r1 = r1.order_by('period__weekday', 'period__period').distinct()
# simple list of their PKs
all = list(res.values_list('pk', flat=True))
all = list(r1.values_list('pk', flat=True))
if len(all) < 1:
return None
# next one after ourselves, wrapping around
next = all[(all.index(self.pk) + 1) % len(all)]
return LessonPeriod.objects.get(pk=next)
thisindex = all.index(self.pk)
notwrapped = thisindex < len(all) - 1
candidate_pk = all[(thisindex + 1) % len(all)]
candidate = LessonPeriod.objects.get(pk=candidate_pk)
# same day?
if notwrapped and candidate.period.weekday == self.period.weekday:
return candidate
# calculate day offset
dstday = candidate.period.weekday
if not notwrapped:
dstday = dstday + 7
dayofs = dstday - self.period.weekday
# Stundenplan still valid?
thiscw = self.lesson.get_calendar_week(self._week)
thisdate = week_weekday_to_date(thiscw, self.period.weekday)
#… tbd
def __str__(self) -> str:
return '%s, %d., %s, %s' % (self.period.get_weekday_display(), self.period.period,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment