From ffe66828a5f18fe585225a6731e37f2e8b46f36c Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Mon, 1 Feb 2021 17:33:22 +0100 Subject: [PATCH] Make carry over of personal notes to following periods configurable --- aleksis/apps/alsijil/preferences.py | 8 ++++++++ aleksis/apps/alsijil/views.py | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/aleksis/apps/alsijil/preferences.py b/aleksis/apps/alsijil/preferences.py index 4ced04f41..bd51c03e8 100644 --- a/aleksis/apps/alsijil/preferences.py +++ b/aleksis/apps/alsijil/preferences.py @@ -46,6 +46,14 @@ class CarryOverDataToNextPeriods(BooleanPreference): help_text = _("This will carry over data only if the data in the following periods are empty.") +@site_preferences_registry.register +class CarryOverPersonalNotesToNextPeriods(BooleanPreference): + section = alsijil + name = "carry_over_personal_notes" + default = True + verbose_name = _("Carry over personal notes to all following lesson periods on the same day.") + + @site_preferences_registry.register class AllowOpenPeriodsOnSameDay(BooleanPreference): section = alsijil diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py index 2b49259d9..397019f31 100644 --- a/aleksis/apps/alsijil/views.py +++ b/aleksis/apps/alsijil/views.py @@ -153,17 +153,19 @@ def lesson( reversion.set_user(request.user) instances = personal_note_formset.save() - # Iterate over personal notes and carry changed absences to following lessons - with reversion.create_revision(): - reversion.set_user(request.user) - for instance in instances: - instance.person.mark_absent( - wanted_week[lesson_period.period.weekday], - lesson_period.period.period + 1, - instance.absent, - instance.excused, - instance.excuse_type, - ) + if get_site_preferences()["alsijil__carry_over_personal_notes"]: + # Iterate over personal notes + # and carry changed absences to following lessons + with reversion.create_revision(): + reversion.set_user(request.user) + for instance in instances: + instance.person.mark_absent( + wanted_week[lesson_period.period.weekday], + lesson_period.period.period + 1, + instance.absent, + instance.excused, + instance.excuse_type, + ) messages.success(request, _("The personal notes have been saved.")) -- GitLab