diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3b20da11fff218384dd4f826c44e45f8f45a7d67..c20f8d4f72b0e3b658e14ee6cba680198e137b0a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,7 +12,8 @@ Unreleased Fixed ~~~~~ -* The week and lesson period fields in the edit substitution form could be changed. +* The week and lesson period fields in the edit substitution form could be changed + and the comment field was missing. `2.4`_ - 2022-06-23 ------------------- diff --git a/aleksis/apps/chronos/forms.py b/aleksis/apps/chronos/forms.py index cbec05e91df886da00703c768ac76e882b1bd6c6..b1cfb87efc18b65c38fbdcce7a9a0361f82ca9dd 100644 --- a/aleksis/apps/chronos/forms.py +++ b/aleksis/apps/chronos/forms.py @@ -11,7 +11,7 @@ class LessonSubstitutionForm(forms.ModelForm): class Meta: model = LessonSubstitution - fields = ["subject", "teachers", "room", "cancelled"] + fields = ["subject", "teachers", "room", "cancelled", "comment"] widgets = { "teachers": ModelSelect2MultipleWidget( search_fields=[ diff --git a/aleksis/apps/chronos/views.py b/aleksis/apps/chronos/views.py index de21fe4584f06ac8fd7c622618ff87bbbed98058..4613d2064859ff3c0e32d246fe27a7146669982b 100644 --- a/aleksis/apps/chronos/views.py +++ b/aleksis/apps/chronos/views.py @@ -249,7 +249,8 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse lesson_period = get_object_or_404(LessonPeriod, pk=id_) wanted_week = lesson_period.lesson.get_calendar_week(week) context["lesson_period"] = lesson_period - context["date"] = week_weekday_to_date(wanted_week, lesson_period.period.weekday) + day = week_weekday_to_date(wanted_week, lesson_period.period.weekday) + context["date"] = day lesson_substitution = get_substitution_by_id(request, id_, week) @@ -260,7 +261,6 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse else: edit_substitution_form = LessonSubstitutionForm( request.POST or None, - initial={"week": wanted_week.week, "lesson_period": lesson_period}, ) context["substitution"] = lesson_substitution @@ -273,11 +273,11 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse lesson_substitution.week = wanted_week.week lesson_substitution.year = wanted_week.year lesson_substitution.save() + edit_substitution_form.save_m2m() messages.success(request, _("The substitution has been saved.")) - date = wanted_week[lesson_period.period.weekday] - return redirect("lessons_day_by_date", year=date.year, month=date.month, day=date.day) + return redirect("lessons_day_by_date", year=day.year, month=day.month, day=day.day) context["edit_substitution_form"] = edit_substitution_form