From 9c422c5bd8f3f75a44b3723eb82b65696a28d959 Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Thu, 24 Oct 2024 21:13:30 +0200
Subject: [PATCH] Adapt the register_abbreviations to the new datamodel

---
 aleksis/apps/alsijil/tasks.py                 |  6 +++
 .../partials/register_abbreviations.html      | 45 +++++++------------
 2 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/aleksis/apps/alsijil/tasks.py b/aleksis/apps/alsijil/tasks.py
index 8beaefbcb..59459dbc6 100644
--- a/aleksis/apps/alsijil/tasks.py
+++ b/aleksis/apps/alsijil/tasks.py
@@ -15,6 +15,7 @@ from aleksis.core.util.celery_progress import ProgressRecorder, recorded_task
 from aleksis.core.util.pdf import generate_pdf_from_template
 
 from aleksis.apps.cursus.models import Course
+from aleksis.apps.kolego.models.absence import AbsenceReason
 
 from .models import ExtraMark
 
@@ -162,6 +163,11 @@ def generate_full_register_printout(
     if include_cover:
         group = group.select_related("school_term")
 
+    if include_abbreviations:
+        # TODO: AbsenceReasonTag important?
+        context["absence_reasons"] = AbsenceReason.objects.all()
+        context["extra_marks"] = ExtraMark.objects.all()
+
     if include_teachers_and_subjects_table:
         group = group.prefetch_related(
             "courses",
diff --git a/aleksis/apps/alsijil/templates/alsijil/partials/register_abbreviations.html b/aleksis/apps/alsijil/templates/alsijil/partials/register_abbreviations.html
index 12ad365d0..4d6377ad4 100644
--- a/aleksis/apps/alsijil/templates/alsijil/partials/register_abbreviations.html
+++ b/aleksis/apps/alsijil/templates/alsijil/partials/register_abbreviations.html
@@ -1,42 +1,27 @@
 <h4>{% trans "Abbreviations" %}</h4>
 
-<h5>{% trans "General" %}</h5>
-
-<ul class="collection">
-  <li class="collection-item">
-    <strong>(a)</strong> {% trans "Absent" %}
-  </li>
-  <li class="collection-item">
-    <strong>(b)</strong> {% trans "Late" %}
-  </li>
-  <li class="collection-item">
-    <strong>(u)</strong> {% trans "Unexcused" %}
-  </li>
-  <li class="collection-item">
-    <strong>(e)</strong> {% trans "Excused" %}
-  </li>
-</ul>
-
-{% if excuse_types %}
-  <h5>{% trans "Custom excuse types" %}</h5>
+{% if absence_reasons %}
+  <h5>{% trans "Absence reasons" %}</h5>
 
   <ul class="collection">
-    {% for excuse_type in excuse_types %}
-      <li class="collection-item">
-        <strong>({{ excuse_type.short_name }})</strong> {{ excuse_type.name }}
-      </li>
+    {% for absence_reason in absence_reasons %}
+      {% if absence_reason.count_as_absent %}
+        <li class="collection-item">
+          <strong>({{ absence_reason.short_name }})</strong> {{ absence_reason.name }}
+        </li>
+      {% endif %}
     {% endfor %}
   </ul>
-{% endif %}
 
-{% if excuse_types_not_absent %}
-  <h5>{% trans "Custom excuse types (not counted as absent)" %}</h5>
+  <h5>{% trans "Absence reasons (not counted as absent)" %}</h5>
 
   <ul class="collection">
-    {% for excuse_type in excuse_types_not_absent %}
-      <li class="collection-item">
-        <strong>({{ excuse_type.short_name }})</strong> {{ excuse_type.name }}
-      </li>
+    {% for absence_reason in absence_reasons %}
+      {% if not absence_reason.count_as_absent %}
+        <li class="collection-item">
+          <strong>({{ absence_reason.short_name }})</strong> {{ absence_reason.name }}
+        </li>
+      {% endif %}
     {% endfor %}
   </ul>
 {% endif %}
-- 
GitLab