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): ...@@ -111,44 +111,43 @@ class LessonDocumentation(ExtensibleModel):
Can be deactivated using site preference ``alsijil__carry_over``. Can be deactivated using site preference ``alsijil__carry_over``.
""" """
if get_site_preferences()["alsijil__carry_over"] and ( try:
self.topic or self.homework or self.group_note second_period = LessonPeriod.objects.get(
): lesson=self.lesson_period.lesson,
try: period__weekday=self.lesson_period.period.weekday,
second_period = LessonPeriod.objects.get( period__period=self.lesson_period.period.period + 1,
lesson=self.lesson_period.lesson, )
period__weekday=self.lesson_period.period.weekday, lesson_documentation = second_period.get_or_create_lesson_documentation(
period__period=self.lesson_period.period.period + 1, CalendarWeek(
) week=self.week, year=self.lesson_period.lesson.get_year(self.week),
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: if not lesson_documentation.topic:
lesson_documentation.topic = self.topic lesson_documentation.topic = self.topic
changed = True changed = True
if not lesson_documentation.homework: if not lesson_documentation.homework:
lesson_documentation.homework = self.homework lesson_documentation.homework = self.homework
changed = True changed = True
if not lesson_documentation.group_note: if not lesson_documentation.group_note:
lesson_documentation.group_note = self.group_note lesson_documentation.group_note = self.group_note
changed = True changed = True
if changed: if changed:
lesson_documentation.save() lesson_documentation.save()
except LessonPeriod.DoesNotExist: except LessonPeriod.DoesNotExist:
# Do nothing if it's a single period # Do nothing if it's a single period
pass pass
def save(self, *args, **kwargs): 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) super().save(*args, **kwargs)
class Meta: 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