From 2197e68083929e11e35c23e930a83b483e904afb Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Tue, 14 Jul 2020 21:15:56 +0200
Subject: [PATCH] [Full register printout] Show statistics on extra marks and
 personal notes with extra marks

---
 .../alsijil/print/full_register.html          | 33 +++++++++++++++++--
 aleksis/apps/alsijil/views.py                 | 10 ++++++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/aleksis/apps/alsijil/templates/alsijil/print/full_register.html b/aleksis/apps/alsijil/templates/alsijil/print/full_register.html
index 91747e211..18298344c 100644
--- a/aleksis/apps/alsijil/templates/alsijil/print/full_register.html
+++ b/aleksis/apps/alsijil/templates/alsijil/print/full_register.html
@@ -77,6 +77,9 @@
       <th>{% trans 'Absences' %}</th>
       <th>{% trans 'Unexcused' %}</th>
       <th>{% trans 'Tard.' %}</th>
+      {% for extra_mark in extra_marks %}
+        <th>{{ extra_mark.short_name }}</th>
+      {% endfor %}
     </tr>
     </thead>
 
@@ -91,6 +94,9 @@
         <td>{{ person.absences_count }}</td>
         <td>{{ person.unexcused }}</td>
         <td>{{ person.tardiness }}'</td>
+        {% for extra_mark in extra_marks %}
+          <td>{{ person|get_dict:extra_mark.count_label }}</td>
+        {% endfor %}
       </tr>
     {% endfor %}
     </tbody>
@@ -243,6 +249,18 @@
       </tbody>
     </table>
 
+    {% if extra_marks %}
+      <h5>{% trans 'Extra marks' %}</h5>
+      <table>
+        {% for extra_mark in extra_marks %}
+          <tr>
+            <th>{{ extra_mark.name }}</th>
+            <td>{{ person|get_dict:extra_mark.count_label }}</td>
+          </tr>
+        {% endfor %}
+      </table>
+    {% endif %}
+
     <h5>{% trans 'Relevant personal notes' %}</h5>
     <table class="small-print">
       <thead>
@@ -253,13 +271,13 @@
         <th>{% trans 'Te.' %}</th>
         <th>{% trans 'Absent' %}</th>
         <th>{% trans 'Tard.' %}</th>
-        <th>{% trans 'Remarks' %}</th>
+        <th colspan="2">{% trans 'Remarks' %}</th>
       </tr>
       </thead>
 
       <tbody>
       {% for note in person.personal_notes.all %}
-        {% if note.absent or note.late or note.remarks %}
+        {% if note.absent or note.late or note.remarks or note.extra_marks.all %}
           {% period_to_date note.week note.lesson_period.period as note_date %}
           <tr>
             <td>{{ note_date }}</td>
@@ -279,6 +297,11 @@
                 {{ note.late }}'
               {% endif %}
             </td>
+            <td>
+              {% for extra_mark in note.extra_marks.all %}
+                {{ extra_mark.short_name }}{% if not forloop.last %},{% endif %}
+              {% endfor %}
+            </td>
             <td>{{ note.remarks }}</td>
           </tr>
         {% endif %}
@@ -363,6 +386,12 @@
                       {% endif %}
                       </span>
                   {% endif %}
+                  {% for extra_mark in note.extra_marks.all %}
+                    <span>
+                      {{ note.person.last_name }}, {{ note.person.first_name|slice:"0:1" }}.
+                      ({{ extra_mark.short_name }})
+                    </span>
+                  {% endfor %}
                 {% endfor %}
               </td>
               <td class="lesson-te">
diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py
index 43d1db178..4231ea11e 100644
--- a/aleksis/apps/alsijil/views.py
+++ b/aleksis/apps/alsijil/views.py
@@ -332,6 +332,15 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
         tardiness=Sum("personal_notes__late"),
     )
 
+    for extra_mark in ExtraMark.objects.all():
+        persons = persons.annotate(
+            **{
+                extra_mark.count_label: Count(
+                    "personal_notes", filter=Q(personal_notes__extra_marks=extra_mark,),
+                )
+            }
+        )
+
     # FIXME Move to manager
     personal_note_filters = PersonalNoteFilter.objects.all()
     for personal_note_filter in personal_note_filters:
@@ -347,6 +356,7 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
             }
         )
 
+    context["extra_marks"] = ExtraMark.objects.all()
     context["persons"] = persons
     context["personal_note_filters"] = personal_note_filters
     context["group"] = group
-- 
GitLab