Skip to content
Snippets Groups Projects
Verified Commit 07b21b13 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix substituion form again and add comment field

parent 7c464908
No related branches found
No related tags found
1 merge request!270Fix substitution form again and add comment field
Pipeline #84424 failed
...@@ -12,7 +12,8 @@ Unreleased ...@@ -12,7 +12,8 @@ Unreleased
Fixed 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 `2.4`_ - 2022-06-23
------------------- -------------------
......
...@@ -11,7 +11,7 @@ class LessonSubstitutionForm(forms.ModelForm): ...@@ -11,7 +11,7 @@ class LessonSubstitutionForm(forms.ModelForm):
class Meta: class Meta:
model = LessonSubstitution model = LessonSubstitution
fields = ["subject", "teachers", "room", "cancelled"] fields = ["subject", "teachers", "room", "cancelled", "comment"]
widgets = { widgets = {
"teachers": ModelSelect2MultipleWidget( "teachers": ModelSelect2MultipleWidget(
search_fields=[ search_fields=[
......
...@@ -249,7 +249,8 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse ...@@ -249,7 +249,8 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse
lesson_period = get_object_or_404(LessonPeriod, pk=id_) lesson_period = get_object_or_404(LessonPeriod, pk=id_)
wanted_week = lesson_period.lesson.get_calendar_week(week) wanted_week = lesson_period.lesson.get_calendar_week(week)
context["lesson_period"] = lesson_period 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) lesson_substitution = get_substitution_by_id(request, id_, week)
...@@ -260,7 +261,6 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse ...@@ -260,7 +261,6 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse
else: else:
edit_substitution_form = LessonSubstitutionForm( edit_substitution_form = LessonSubstitutionForm(
request.POST or None, request.POST or None,
initial={"week": wanted_week.week, "lesson_period": lesson_period},
) )
context["substitution"] = lesson_substitution context["substitution"] = lesson_substitution
...@@ -273,11 +273,11 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse ...@@ -273,11 +273,11 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse
lesson_substitution.week = wanted_week.week lesson_substitution.week = wanted_week.week
lesson_substitution.year = wanted_week.year lesson_substitution.year = wanted_week.year
lesson_substitution.save() lesson_substitution.save()
edit_substitution_form.save_m2m()
messages.success(request, _("The substitution has been saved.")) messages.success(request, _("The substitution has been saved."))
date = wanted_week[lesson_period.period.weekday] return redirect("lessons_day_by_date", year=day.year, month=day.month, day=day.day)
return redirect("lessons_day_by_date", year=date.year, month=date.month, day=date.day)
context["edit_substitution_form"] = edit_substitution_form context["edit_substitution_form"] = edit_substitution_form
......
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