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

Move settings check for carry_data_over to save method

Makes it possible to use the function in other contexts
parent 5914e36b
No related branches found
No related tags found
1 merge request!79Resolve "Carry over the data of the first lesson for double (or triple, ...) lessons"
......@@ -111,44 +111,43 @@ class LessonDocumentation(ExtensibleModel):
Can be deactivated using site preference ``alsijil__carry_over``.
"""
if get_site_preferences()["alsijil__carry_over"] and (
self.topic or self.homework or self.group_note
):
try:
second_period = 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_period.get_or_create_lesson_documentation(
CalendarWeek(
week=self.week,
year=self.lesson_period.lesson.get_year(self.week),
)
try:
second_period = 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_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 period
pass
if changed:
lesson_documentation.save()
except LessonPeriod.DoesNotExist:
# Do nothing if it's a single period
pass
def save(self, *args, **kwargs):
self._carry_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:
......
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