Skip to content
Snippets Groups Projects
Verified Commit 943bd90e authored by Hangzhi Yu's avatar Hangzhi Yu Committed by magicfelix
Browse files

Add option to set LessonDocumentation data for all lessons in one week at once

parent ce9f31f9
No related branches found
No related tags found
1 merge request!267Resolve "Allow lesson documentation to be edited for all lessons of one subject and one week at once"
Pipeline #66500 passed with warnings
......@@ -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
~~~~~
......
......@@ -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):
......
......@@ -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:
......
......@@ -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
......
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