From c929a26eb67a34a3727d7568e6098453c23489f6 Mon Sep 17 00:00:00 2001
From: Tom Teichler <tom.teichler@teckids.org>
Date: Sat, 2 Nov 2019 21:09:45 +0100
Subject: [PATCH] Add sum of absences and tardiness to printout.

---
 .../templates/alsijil/print/full_register.html       |  8 +++++++-
 biscuit/apps/alsijil/views.py                        | 12 ++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/biscuit/apps/alsijil/templates/alsijil/print/full_register.html b/biscuit/apps/alsijil/templates/alsijil/print/full_register.html
index 6170527d6..1227797c3 100644
--- a/biscuit/apps/alsijil/templates/alsijil/print/full_register.html
+++ b/biscuit/apps/alsijil/templates/alsijil/print/full_register.html
@@ -67,17 +67,23 @@
             <th>{% trans 'First name' %}</th>
             <th>{% trans 'Sex' %}</th>
             <th>{% trans 'Date of birth' %}</th>
+            <th>{% trans 'Absences' %}</th>
+            <th>{% trans 'Unexcused' %}</th>
+            <th>{% trans 'Tard.' %}</th>
           </tr>
         </thead>
 
         <tbody>
-          {% for person in group.members.all %}
+          {% for person in persons %}
             <tr>
               <td>{{ forloop.counter }}</td>
               <td>{{ person.last_name }}</td>
               <td>{{ person.first_name }}</td>
               <td>{{ person.get_sex_display }}</td>
               <td>{{ person.date_of_birth }}</td>
+              <td>{{ person.absences}}</td>
+              <td>{{ person.unexcused }}</td>
+              <td>{{ person.tardiness }}</td>
             </tr>
           {% endfor %}
         </tbody>
diff --git a/biscuit/apps/alsijil/views.py b/biscuit/apps/alsijil/views.py
index a0f1b1b74..f31b14af1 100644
--- a/biscuit/apps/alsijil/views.py
+++ b/biscuit/apps/alsijil/views.py
@@ -182,6 +182,18 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
 
                 periods_by_day.setdefault(day, []).append((lesson_period, documentations, notes, substitution))
 
+    persons = group.members.annotate(
+            absences=Count('personal_notes__absent', filter=Q(
+                personal_notes__absent=True
+            )),
+            unexcused=Count('personal_notes__absent', filter=Q(
+                personal_notes__absent=True,
+                personal_notes__excused=False
+            )),
+            tardiness=Sum('personal_notes__late')
+        )
+
+    context['persons'] = persons
     context['group'] = group
     context['weeks'] = weeks
     context['periods_by_day'] = periods_by_day
-- 
GitLab