From 58301524ca3454f360063e33394319a169fc9b77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?=
 <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de>
Date: Sun, 9 May 2021 01:34:41 +0200
Subject: [PATCH] Display list of next AKs on slides

---
 .../templates/admin/AKModel/export/slides.tex | 26 +++++++++++++++----
 AKModel/views.py                              | 24 +++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/AKModel/templates/admin/AKModel/export/slides.tex b/AKModel/templates/admin/AKModel/export/slides.tex
index d7c9ce62..814c57ed 100644
--- a/AKModel/templates/admin/AKModel/export/slides.tex
+++ b/AKModel/templates/admin/AKModel/export/slides.tex
@@ -28,11 +28,11 @@
 \end{frame}
 
 
-{%for category in categories %}
+{%for category, ak_list in categories_with_aks %}
 
     \section{ {{- category.name | latex_escape_utf8 -}} }
 
-    {% for ak in category.ak_set.all() %}
+    {% for ak, next_aks in ak_list %}
 
         {% if not ak.wish %}
 
@@ -51,7 +51,15 @@
                     \faScroll
                 {% endif %}
 
-                {{ ak.description | truncatechars(500) | latex_escape_utf8 }}
+                {{ ak.description | truncatechars(400) | latex_escape_utf8 }}
+
+                \vspace{2em}
+
+                \begin{scriptsize}
+                    {% for n_ak in next_aks %}
+                        {% if n_ak %}\hfill \faAngleDoubleRight~ {{- n_ak.name | latex_escape_utf8 -}}{% endif %}
+                    {% endfor %}
+                \end{scriptsize}
 
             \end{frame}
 
@@ -64,7 +72,7 @@
 
 \section{ {{- translations.wishes -}} }
 
-{% for ak in wishes %}
+{% for ak, next_aks in wishes %}
 
     %\setbeamertemplate{frame footer}{}
 
@@ -79,7 +87,15 @@
 
         \faClock~
 
-        {{ ak.description | truncatechars(500) | latex_escape_utf8 }}
+        {{ ak.description | truncatechars(400) | latex_escape_utf8 }}
+
+        \vspace{2em}
+
+        \begin{scriptsize}
+            {% for n_ak in next_aks %}
+                {% if n_ak %}\hfill \faAngleDoubleRight~ {{- n_ak.name | latex_escape_utf8 -}}{% endif %}
+            {% endfor %}
+        \end{scriptsize}
 
     \end{frame}
 
diff --git a/AKModel/views.py b/AKModel/views.py
index b620f1e7..06bd3211 100644
--- a/AKModel/views.py
+++ b/AKModel/views.py
@@ -1,3 +1,5 @@
+from itertools import zip_longest
+
 from django.contrib import admin, messages
 from django.contrib.admin.views.decorators import staff_member_required
 from django.http import HttpResponseRedirect
@@ -296,6 +298,8 @@ def export_slides(request, event_slug):
 
     event = get_object_or_404(Event, slug=event_slug)
 
+    NEXT_AK_LIST_LENGTH = 4
+
     translations = {
         'symbols': _("Symbols"),
         'who': _("Who?"),
@@ -305,11 +309,27 @@ def export_slides(request, event_slug):
         'wishes': _("Wishes"),
     }
 
+    def build_ak_list_with_next_aks(ak_list):
+        next_aks_list = zip_longest(*[ak_list[i + 1:] for i in range(NEXT_AK_LIST_LENGTH)], fillvalue=None)
+        return [(ak, next_aks) for ak, next_aks in zip_longest(ak_list, next_aks_list, fillvalue=list())]
+
+    categories = event.akcategory_set.all()
+    categories_with_aks = []
+    ak_wishes = []
+    for category in categories:
+        ak_list = []
+        for ak in category.ak_set.all(): # order_by("owners").distinct():
+            if ak.wish:
+                ak_wishes.append(ak)
+            else:
+                ak_list.append(ak)
+        categories_with_aks.append((category, build_ak_list_with_next_aks(ak_list)))
+
     context = {
         'title': event.name,
-        'categories': event.akcategory_set.all(),
+        'categories_with_aks': categories_with_aks,
         'subtitle': _("AKs"),
-        "wishes": [ak for ak in event.ak_set.order_by('category') if ak.wish],
+        "wishes": build_ak_list_with_next_aks(ak_wishes),
         "translations": translations,
         }
 
-- 
GitLab