Skip to content
Snippets Groups Projects
Commit f29159e1 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch...

Merge branch '64-make-it-possible-to-take-over-the-data-of-the-first-lesson-for-double-lessons' into 'master'

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

Closes #64

See merge request !79
parents e08075f9 ab9818de
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"
Pipeline #3459 passed
from django.db import models
from django.utils.translation import gettext_lazy as _
from calendarweek import CalendarWeek
from aleksis.apps.chronos.models import LessonPeriod
from aleksis.core.mixins import ExtensibleModel
from aleksis.core.util.core_helpers import get_site_preferences
def isidentifier(value: str) -> bool:
......@@ -102,6 +106,47 @@ class LessonDocumentation(ExtensibleModel):
verbose_name=_("Group note"), max_length=200, blank=True
)
def _carry_over_data(self):
"""Carry over data to directly adjacent periods in this lesson if data is not already set.
Can be deactivated using site preference ``alsijil__carry_over``.
"""
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
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.group_note:
lesson_documentation.group_note = self.group_note
changed = True
if changed:
lesson_documentation.save()
def save(self, *args, **kwargs):
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:
verbose_name = _("Lesson documentation")
verbose_name_plural = _("Lesson documentations")
......
......@@ -14,3 +14,16 @@ class BlockPersonalNotesForCancelled(BooleanPreference):
name = "block_personal_notes_for_cancelled"
default = True
verbose_name = _("Block adding personal notes for cancelled lessons")
@site_preferences_registry.register
class CarryOverDataToNextPeriods(BooleanPreference):
section = alsijil
name = "carry_over"
default = True
verbose_name = _(
"Carry over data from first lesson period to the following lesson periods in lessons over multiple periods"
)
help_text = _(
"This will carry over data only if the data in the following periods are empty."
)
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