diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9908ea032bc2a3b96d42b1c4ad01fbfee7c2153d..f7279f451fda09da09f32f6379319f0fca3b20b0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ Added ~~~~~ * Integrate seating plans in lesson overview +* Add option to set LessonDocumentation data for all lessons in one week at once. Fixed ~~~~~ diff --git a/aleksis/apps/alsijil/forms.py b/aleksis/apps/alsijil/forms.py index 144188edf6599ddbe8f4c4d9a01828ab4b56dbf0..6f4e65b2022192c3cf5c0a7c4b44cc3e1731919e 100644 --- a/aleksis/apps/alsijil/forms.py +++ b/aleksis/apps/alsijil/forms.py @@ -13,7 +13,7 @@ from guardian.shortcuts import get_objects_for_user from material import Fieldset, Layout, Row from aleksis.apps.chronos.managers import TimetableType -from aleksis.apps.chronos.models import Subject, TimePeriod +from aleksis.apps.chronos.models import LessonPeriod, Subject, TimePeriod from aleksis.core.forms import ActionForm, ListActionForm from aleksis.core.models import Group, Person, SchoolTerm from aleksis.core.util.core_helpers import get_site_preferences @@ -45,6 +45,30 @@ class LessonDocumentationForm(forms.ModelForm): super().__init__(*args, **kwargs) self.fields["homework"].label = _("Homework for the next lesson") + if ( + self.instance.lesson_period + and get_site_preferences()["alsijil__allow_carry_over_same_week"] + ): + self.fields["carry_over_week"] = forms.BooleanField( + label=_("Carry over data to all other lessons with the same subject in this week"), + initial=True, + required=False, + ) + + def save(self, **kwargs): + lesson_documentation = super(LessonDocumentationForm, self).save(commit=True) + if ( + self.cleaned_data["carry_over_week"] + and ( + lesson_documentation.topic + or lesson_documentation.homework + or lesson_documentation.group_note + ) + and lesson_documentation.lesson_period + ): + lesson_documentation.carry_over_data( + LessonPeriod.objects.filter(lesson=lesson_documentation.lesson_period.lesson) + ) class PersonalNoteForm(forms.ModelForm): diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 54e8be9c3bbdab2f2603ca423ec54f38550e22d5..b8189119f601b4ba8348d6fff94dd6de0c8fa0a2 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -337,15 +337,13 @@ class LessonDocumentation(RegisterObjectRelatedMixin, ExtensibleModel): homework = models.CharField(verbose_name=_("Homework"), max_length=200, blank=True) group_note = models.CharField(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. + def carry_over_data(self, all_periods_of_lesson: LessonPeriod): + """Carry over data to given periods in this lesson if data is not already set. - Can be deactivated using site preference ``alsijil__carry_over``. + Both forms of carrying over data can be deactivated using site preferences + ``alsijil__carry_over_next_periods`` and ``alsijil__allow_carry_over_same_week`` + respectively. """ - all_periods_of_lesson = LessonPeriod.objects.filter( - lesson=self.lesson_period.lesson, - period__weekday=self.lesson_period.period.weekday, - ) for period in all_periods_of_lesson: lesson_documentation = period.get_or_create_lesson_documentation( CalendarWeek(week=self.week, year=self.year) @@ -366,19 +364,24 @@ class LessonDocumentation(RegisterObjectRelatedMixin, ExtensibleModel): changed = True if changed: - lesson_documentation.save(carry_over=False) + lesson_documentation.save(carry_over_next_periods=False) def __str__(self) -> str: return f"{self.lesson_period}, {self.date_formatted}" - def save(self, carry_over=True, *args, **kwargs): + def save(self, carry_over_next_periods=True, *args, **kwargs): if ( - get_site_preferences()["alsijil__carry_over"] + get_site_preferences()["alsijil__carry_over_next_periods"] and (self.topic or self.homework or self.group_note) and self.lesson_period - and carry_over + and carry_over_next_periods ): - self._carry_over_data() + self.carry_over_data( + LessonPeriod.objects.filter( + lesson=self.lesson_period.lesson, + period__weekday=self.lesson_period.period.weekday, + ) + ) super().save(*args, **kwargs) class Meta: diff --git a/aleksis/apps/alsijil/preferences.py b/aleksis/apps/alsijil/preferences.py index c563321150ad30a2a3ec54134c3f842c572f4f2e..35d0984effae2264de0e53844682b09eb60ac3f8 100644 --- a/aleksis/apps/alsijil/preferences.py +++ b/aleksis/apps/alsijil/preferences.py @@ -46,7 +46,7 @@ class EditLessonDocumentationAsOriginalTeacher(BooleanPreference): @site_preferences_registry.register class CarryOverDataToNextPeriods(BooleanPreference): section = alsijil - name = "carry_over" + name = "carry_over_next_periods" default = True verbose_name = _( "Carry over data from first lesson period to the " @@ -55,6 +55,20 @@ 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 AllowCarryOverLessonDocumentationToCurrentWeek(BooleanPreference): + section = alsijil + name = "allow_carry_over_same_week" + default = False + verbose_name = _( + "Allow carrying over data from any lesson period to all other lesson \ + periods with the same lesson and in the same week" + ) + help_text = _( + "This will carry over data only if the data in the aforementioned periods are empty." + ) + + @site_preferences_registry.register class CarryOverPersonalNotesToNextPeriods(BooleanPreference): section = alsijil