Skip to content
Snippets Groups Projects

Resolve "Carry over the data of the first lesson for double (or triple, ...) lessons"

Files
2
@@ -106,49 +106,45 @@ class LessonDocumentation(ExtensibleModel):
verbose_name=_("Group note"), max_length=200, blank=True
)
def _take_over_data(self):
"""Take over data to the next lesson, if exists and data are not already set.
def _carry_over_data(self):
"""Carry over data to the next lesson, if exists and data are not already set.
Can be deactivated using site preference ``alsijil__take_over_double``.
Can be deactivated using site preference ``alsijil__carry_over``.
"""
if get_site_preferences()["alsijil__take_over_double"] and (
self.topic or self.homework or self.group_note
):
try:
second_lesson = LessonPeriod.objects.get(
lesson=self.lesson_period.lesson,
period__weekday=self.lesson_period.period.weekday,
period__period=self.lesson_period.period.period + 1,
)
lesson_documentation = second_lesson.get_or_create_lesson_documentation(
CalendarWeek(
week=self.week,
year=self.lesson_period.lesson.get_year(self.week),
)
following_periods = LessonPeriod.objects.filter(
lesson=self.lesson_period.lesson,
period__weekday=self.lesson_period.period.weekday,
period__period__gt=self.lesson_period.period.period,
)
for period in following_periods:
lesson_documentation = period.get_or_create_lesson_documentation(
CalendarWeek(
week=self.week, year=self.lesson_period.lesson.get_year(self.week),
)
)
changed = False
changed = False
if not lesson_documentation.topic:
lesson_documentation.topic = self.topic
changed = True
if not lesson_documentation.topic:
lesson_documentation.topic = self.topic
changed = True
if not lesson_documentation.homework:
lesson_documentation.homework = self.homework
changed = True
if not lesson_documentation.homework:
lesson_documentation.homework = self.homework
changed = True
if not lesson_documentation.group_note:
lesson_documentation.group_note = self.group_note
changed = True
if not lesson_documentation.group_note:
lesson_documentation.group_note = self.group_note
changed = True
if changed:
lesson_documentation.save()
except LessonPeriod.DoesNotExist:
# Do nothing if it's a single lesson
pass
if changed:
lesson_documentation.save()
def save(self, *args, **kwargs):
self._take_over_data()
if get_site_preferences()["alsijil__carry_over"] and (
self.topic or self.homework or self.group_note
):
self._carry_over_data()
super().save(*args, **kwargs)
class Meta:
Loading