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

Add excuse_type to personal note form

parent 79ddcc1c
No related branches found
No related tags found
1 merge request!64Resolve "Add support for multiple excuse types"
...@@ -28,7 +28,7 @@ class LessonDocumentationForm(forms.ModelForm): ...@@ -28,7 +28,7 @@ class LessonDocumentationForm(forms.ModelForm):
class PersonalNoteForm(forms.ModelForm): class PersonalNoteForm(forms.ModelForm):
class Meta: class Meta:
model = PersonalNote model = PersonalNote
fields = ["absent", "late", "excused", "remarks"] fields = ["absent", "late", "excused", "excuse_type", "remarks"]
person_name = forms.CharField(disabled=True) person_name = forms.CharField(disabled=True)
......
...@@ -8,7 +8,7 @@ from calendarweek import CalendarWeek ...@@ -8,7 +8,7 @@ from calendarweek import CalendarWeek
from aleksis.apps.chronos.models import LessonPeriod from aleksis.apps.chronos.models import LessonPeriod
from aleksis.core.models import Group, Person from aleksis.core.models import Group, Person
from .models import LessonDocumentation, PersonalNote from .models import ExcuseType, LessonDocumentation, PersonalNote
@Person.method @Person.method
...@@ -18,6 +18,7 @@ def mark_absent( ...@@ -18,6 +18,7 @@ def mark_absent(
from_period: int = 0, from_period: int = 0,
absent: bool = True, absent: bool = True,
excused: bool = False, excused: bool = False,
excuse_type: Optional[ExcuseType] = None,
remarks: str = "", remarks: str = "",
): ):
"""Mark a person absent for all lessons in a day, optionally starting with a selected period number. """Mark a person absent for all lessons in a day, optionally starting with a selected period number.
...@@ -44,7 +45,7 @@ def mark_absent( ...@@ -44,7 +45,7 @@ def mark_absent(
person=self, person=self,
lesson_period=lesson_period, lesson_period=lesson_period,
week=wanted_week.week, week=wanted_week.week,
defaults={"absent": absent, "excused": excused}, defaults={"absent": absent, "excused": excused, "excuse_type": excuse_type},
) )
if remarks: if remarks:
......
...@@ -144,6 +144,7 @@ ...@@ -144,6 +144,7 @@
<th>{% blocktrans %}Absent{% endblocktrans %}</th> <th>{% blocktrans %}Absent{% endblocktrans %}</th>
<th>{% blocktrans %}Tardiness{% endblocktrans %}</th> <th>{% blocktrans %}Tardiness{% endblocktrans %}</th>
<th>{% blocktrans %}Excused{% endblocktrans %}</th> <th>{% blocktrans %}Excused{% endblocktrans %}</th>
<th>{% blocktrans %}Excuse type{% endblocktrans %}</th>
<th>{% blocktrans %}Remarks{% endblocktrans %}</th> <th>{% blocktrans %}Remarks{% endblocktrans %}</th>
</tr> </tr>
</thead> </thead>
...@@ -172,6 +173,14 @@ ...@@ -172,6 +173,14 @@
<span></span> <span></span>
</label> </label>
</td> </td>
<td>
<div class="input-field">
{{ form.excuse_type }}
<label for="{{ form.excuse_type.id_for_label }}">
{% trans "Excuse type" %}
</label>
</div>
</td>
<td> <td>
<div class="input-field"> <div class="input-field">
{{ form.remarks }} {{ form.remarks }}
......
...@@ -102,6 +102,8 @@ def lesson( ...@@ -102,6 +102,8 @@ def lesson(
if lesson_documentation_form.is_valid(): if lesson_documentation_form.is_valid():
lesson_documentation_form.save() lesson_documentation_form.save()
messages.success(request, _("The lesson documentation has been saved."))
if personal_note_formset.is_valid(): if personal_note_formset.is_valid():
instances = personal_note_formset.save() instances = personal_note_formset.save()
...@@ -112,8 +114,16 @@ def lesson( ...@@ -112,8 +114,16 @@ def lesson(
lesson_period.period.period + 1, lesson_period.period.period + 1,
instance.absent, instance.absent,
instance.excused, instance.excused,
instance.excuse_type,
) )
messages.success(request, _("The personal notes have been saved."))
# Regenerate form here to ensure that programmatically changed data will be shown correctly
personal_note_formset = PersonalNoteFormSet(
None, queryset=persons_qs, prefix="personal_notes"
)
context["lesson_documentation"] = lesson_documentation context["lesson_documentation"] = lesson_documentation
context["lesson_documentation_form"] = lesson_documentation_form context["lesson_documentation_form"] = lesson_documentation_form
context["personal_note_formset"] = personal_note_formset context["personal_note_formset"] = personal_note_formset
......
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