From ee380d9cee970349dd314906620b9da5b2deeb22 Mon Sep 17 00:00:00 2001
From: Dominik George <nik@naturalnet.de>
Date: Tue, 19 Nov 2019 23:37:52 +0100
Subject: [PATCH] Allow adding remarks when marking absences for full days.

---
 biscuit/apps/alsijil/forms.py            | 1 +
 biscuit/apps/alsijil/model_extensions.py | 7 ++++---
 biscuit/apps/alsijil/views.py            | 3 ++-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/biscuit/apps/alsijil/forms.py b/biscuit/apps/alsijil/forms.py
index fcadb1e92..324656931 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 6cf7a9b53..728d14640 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 5f6048253..3a521d695 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.'))
-- 
GitLab