diff --git a/biscuit/apps/alsijil/forms.py b/biscuit/apps/alsijil/forms.py index fcadb1e92eca4fd26a932be93842705c37584d13..324656931b585b5ae158445cb2bff8702cb99e98 100644 --- a/biscuit/apps/alsijil/forms.py +++ b/biscuit/apps/alsijil/forms.py @@ -57,3 +57,4 @@ class ManageAbsenceForm(forms.Form): person = forms.ModelChoiceField(label=_('Person'), queryset=Person.objects.all(), widget=Select2Widget) absent = forms.BooleanField(label=_('Absent'), initial=True, required=False) excused = forms.BooleanField(label=_('Excused'), initial=True, required=False) + remarks = forms.CharField(label=_('Remarks'), max_length=30, required=False) diff --git a/biscuit/apps/alsijil/model_extensions.py b/biscuit/apps/alsijil/model_extensions.py index 6cf7a9b53d41fd90ffc315bdb41a28cfb9819fec..728d14640ce0f94b0efd39a47e6f83b96e8223e8 100644 --- a/biscuit/apps/alsijil/model_extensions.py +++ b/biscuit/apps/alsijil/model_extensions.py @@ -1,7 +1,7 @@ from datetime import date from typing import Optional -from django.db.models import Exists, OuterRef +from django.db.models import Exists, F, OuterRef from biscuit.apps.chronos.models import LessonPeriod from biscuit.apps.chronos.util import CalendarWeek @@ -11,7 +11,7 @@ from .models import PersonalNote @Person.method -def mark_absent(self, day: date, starting_period: Optional[int] = 0, absent=True, excused=False): +def mark_absent(self, day: date, starting_period: Optional[int] = 0, absent=True, excused=False, remarks=''): """ Mark a person absent for all lessons in a day, optionally starting with a selected period number. @@ -42,7 +42,8 @@ def mark_absent(self, day: date, starting_period: Optional[int] = 0, absent=True week=wanted_week.week, defaults={ 'absent': absent, - 'excused': excused + 'excused': excused, + 'remarks': F('remarks') + remarks } ) diff --git a/biscuit/apps/alsijil/views.py b/biscuit/apps/alsijil/views.py index 5f6048253667e9935438190f7ca51accb7e4f57e..3a521d6958d38bce192f6dd6d92804df22d241fe 100644 --- a/biscuit/apps/alsijil/views.py +++ b/biscuit/apps/alsijil/views.py @@ -221,13 +221,14 @@ def manage_absence(request: HttpRequest) -> HttpResponse: starting_lesson = manage_absence_form.cleaned_data['starting_lesson'] absent = manage_absence_form.cleaned_data['absent'] excused = manage_absence_form.cleaned_data['excused'] + remarks = manage_absence_form.cleaned_data=['remarks'] # Mark person as absent delta = end_date - start_date for i in range(delta.days): starting_period = starting_lesson if i == 0 else 0 day = start_date + timedelta(days=1) - person.mark_absent(day, starting_period=starting_period, absent=absent, excused=excused) + person.mark_absent(day, starting_period=starting_period, absent=absent, excused=excused, remarks=remarks) person.save() messages.success(request, _('The absence has been saved.'))