From 6dfccf0d464b3a7a77c39693d8b66a460bbbe5fc Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sat, 11 Jul 2020 21:55:19 +0200
Subject: [PATCH] Show excuse types in full register

---
 .../static/css/alsijil/full_register.css      |  4 +-
 .../templates/alsijil/partials/absences.html  |  2 +-
 .../alsijil/print/full_register.html          | 60 +++++++++++++++----
 aleksis/apps/alsijil/views.py                 | 22 +++++++
 4 files changed, 73 insertions(+), 15 deletions(-)

diff --git a/aleksis/apps/alsijil/static/css/alsijil/full_register.css b/aleksis/apps/alsijil/static/css/alsijil/full_register.css
index 2c7327003..9a3dc493a 100644
--- a/aleksis/apps/alsijil/static/css/alsijil/full_register.css
+++ b/aleksis/apps/alsijil/static/css/alsijil/full_register.css
@@ -1,4 +1,4 @@
-table.small-print {
+table.small-print, td.small-print, th.small-print {
     font-size: 10pt;
 }
 
@@ -25,7 +25,7 @@ tr.lessons-day-first {
     border-top: 3px solid rgba(0, 0, 0, 0.3);
 }
 
-th.lessons-day-head {
+th.lessons-day-head, td.rotate, th.rotate {
     text-align: center;
     transform: rotate(-90deg);
 }
diff --git a/aleksis/apps/alsijil/templates/alsijil/partials/absences.html b/aleksis/apps/alsijil/templates/alsijil/partials/absences.html
index 6584142bf..6deaa3891 100644
--- a/aleksis/apps/alsijil/templates/alsijil/partials/absences.html
+++ b/aleksis/apps/alsijil/templates/alsijil/partials/absences.html
@@ -1,6 +1,6 @@
 {% load i18n %}
 {% for note in notes %}
   <span class="{% if note.excused %}green-text{% else %}red-text{% endif %}">{{ note.person }}
-    {% if note.excused %}{% trans "(e)" %}{% else %}{% trans "(u)" %}{% endif %}{% if not forloop.last %},{% endif %}
+    {% if note.excused %}{% if note.excuse_type %}({{ note.excuse_type.short_name }}){% else %}{% trans "(e)" %}{% endif %}{% else %}{% trans "(u)" %}{% endif %}{% if not forloop.last %},{% endif %}
   </span>
 {% endfor %}
diff --git a/aleksis/apps/alsijil/templates/alsijil/print/full_register.html b/aleksis/apps/alsijil/templates/alsijil/print/full_register.html
index 91747e211..4f1f61e49 100644
--- a/aleksis/apps/alsijil/templates/alsijil/print/full_register.html
+++ b/aleksis/apps/alsijil/templates/alsijil/print/full_register.html
@@ -74,9 +74,13 @@
       <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>
+      <th>{% trans '(a)' %}</th>
+      <th>{% trans "(e)" %}</th>
+      {% for excuse_type in excuse_types %}
+        <th>({{ excuse_type.short_name }})</th>
+      {% endfor %}
+      <th>{% trans '(u)' %}</th>
+      <th>{% trans '(b)' %}</th>
     </tr>
     </thead>
 
@@ -89,6 +93,10 @@
         <td>{{ person.get_sex_display }}</td>
         <td>{{ person.date_of_birth }}</td>
         <td>{{ person.absences_count }}</td>
+        <td>{{ person.excused }}</td>
+        {% for excuse_type in excuse_types %}
+          <td>{{ person|get_dict:excuse_type.count_label }}</td>
+        {% endfor %}
         <td>{{ person.unexcused }}</td>
         <td>{{ person.tardiness }}'</td>
       </tr>
@@ -226,11 +234,27 @@
 
     <h5>{% trans 'Absences and tardiness' %}</h5>
     <table>
-      <thead>
       <tr>
-        <th>{% trans 'Absences' %}</th>
+        <th colspan="2">{% trans 'Absences' %}</th>
+        <td>{{ person.absences_count }}</td>
+      </tr>
+      <tr>
+        <td rowspan="{{ excuse_types.count|add:2 }}" style="width: 16mm;"
+            class="rotate small-print">{% trans "thereof" %}</td>
+        <th>{% trans 'Excused' %}</th>
+        <td>{{ person.excused }}</td>
+      </tr>
+      {% for excuse_type in excuse_types %}
+        <th>{{ excuse_type.name }}</th>
+        <td>{{ person|get_dict:excuse_type.count_label }}</td>
+      {% endfor %}
+      <tr>
         <th>{% trans 'Unexcused' %}</th>
-        <th>{% trans 'Tardiness' %}</th>
+        <td>{{ person.unexcused }}</td>
+      </tr>
+      <tr>
+        <th colspan="2">{% trans 'Tardiness' %}</th>
+        <td>{{ person.tardiness }}'</td>
       </tr>
       </thead>
 
@@ -269,8 +293,12 @@
             <td>
               {% if note.absent %}
                 {% trans 'Yes' %}
-                {% if note.escused %}
-                  ({% trans 'e' %})
+                {% if note.excused %}
+                  {% if note.excuse_type %}
+                    ({{ note.excuse_type.short_name }})
+                  {% else %}
+                    ({% trans 'e' %})
+                  {% endif %}
                 {% endif %}
               {% endif %}
             </td>
@@ -347,8 +375,12 @@
                       {{ note.person.last_name }}, {{ note.person.first_name|slice:"0:1" }}.
                       {% if note.excused %}
                         <span class="lesson-note-excused">
-                               ({% trans 'e' %})
-                              </span>
+                          {% if note.excuse_type %}
+                            ({{ note.excuse_type.short_name }})
+                          {% else %}
+                            ({% trans 'e' %})
+                          {% endif %}
+                        </span>
                       {% endif %}
                       </span>
                   {% endif %}
@@ -358,8 +390,12 @@
                       ({{ note.late }}′)
                       {% if note.excused %}
                         <span class="lesson-note-excused">
-                               ({% trans 'e' %})
-                              </span>
+                          {% if note.excuse_type %}
+                            ({{ note.excuse_type.short_name }})
+                          {% else %}
+                            ({% trans 'e' %})
+                          {% endif %}
+                        </span>
                       {% endif %}
                       </span>
                   {% endif %}
diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py
index 03e710eeb..b4da5d7e4 100644
--- a/aleksis/apps/alsijil/views.py
+++ b/aleksis/apps/alsijil/views.py
@@ -313,6 +313,14 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
         absences_count=Count(
             "personal_notes__absent", filter=Q(personal_notes__absent=True)
         ),
+        excused=Count(
+            "personal_notes__absent",
+            filter=Q(
+                personal_notes__absent=True,
+                personal_notes__excused=True,
+                personal_notes__excuse_type__isnull=True,
+            ),
+        ),
         unexcused=Count(
             "personal_notes__absent",
             filter=Q(personal_notes__absent=True, personal_notes__excused=False),
@@ -320,6 +328,19 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
         tardiness=Sum("personal_notes__late"),
     )
 
+    for excuse_type in ExcuseType.objects.all():
+        persons = persons.annotate(
+            **{
+                excuse_type.count_label: Count(
+                    "personal_notes__absent",
+                    filter=Q(
+                        personal_notes__absent=True,
+                        personal_notes__excuse_type=excuse_type,
+                    ),
+                )
+            }
+        )
+
     # FIXME Move to manager
     personal_note_filters = PersonalNoteFilter.objects.all()
     for personal_note_filter in personal_note_filters:
@@ -337,6 +358,7 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
 
     context["persons"] = persons
     context["personal_note_filters"] = personal_note_filters
+    context["excuse_types"] = ExcuseType.objects.all()
     context["group"] = group
     context["weeks"] = weeks
     context["periods_by_day"] = periods_by_day
-- 
GitLab