From 54cc1604e06553e86668d0438771574d861cb185 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Fri, 13 Dec 2019 21:49:03 +0100
Subject: [PATCH] Add second day to paper css print view

---
 .../timetable/substitutionprint.html          | 141 +++++++++---------
 biscuit/apps/chronos/urls.py                  |   4 +-
 biscuit/apps/chronos/views.py                 |  65 +++++---
 3 files changed, 117 insertions(+), 93 deletions(-)

diff --git a/biscuit/apps/chronos/templates/timetable/substitutionprint.html b/biscuit/apps/chronos/templates/timetable/substitutionprint.html
index d3b82b03..39363d68 100755
--- a/biscuit/apps/chronos/templates/timetable/substitutionprint.html
+++ b/biscuit/apps/chronos/templates/timetable/substitutionprint.html
@@ -19,93 +19,92 @@
     }
 </style>
 
-<h4>Vertretungen {{ date|date:"l, j. F Y" }}</h4>
+{% for c in days %}
+    <h4>Vertretungen {{ c.date|date:"l, j. F Y" }}</h4>
 
 
-{% include "timetable/hintsinsubprint.html" %}
+    {% include "timetable/hintsinsubprint.html" %}
 
-<div class="row no-print">
-    <div class="col">
-        {% if header_info.is_box_needed %}
-
-            {% for row in header_info.rows %}
+    <div style="margin-bottom: 20px">
+        {% if c.header_info.is_box_needed %}
+            {% for row in c.header_info.rows %}
                 <div class="row no-margin">
-                    <div class="col s3">
+                    <div class="col s3 no-padding">
                         <strong>{{ row.0 }}</strong>
                     </div>
-                    <div class="col s9">
+                    <div class="col s9 no-padding">
                         {{ row.1 }}
                     </div>
                 </div>
             {% endfor %}
-
         {% endif %}
     </div>
-</div>
-
-<table class="substitutions">
-    <thead>
-    <tr>
-        <th><i class="material-icons">people</i></th>
-        <th><i class="material-icons">access_time</i></th>
-        <th>Lehrer</th>
-        <th>Fach</th>
-        <th>Raum</th>
-        <th>Hinweis</th>
-        <th></th>
-    </tr>
-    </thead>
-    <tbody>
-    {% if not sub_table %}
-        <td colspan="7">
-            <p class="flow-text center">
-                Keine Vertretungen vorhanden
-            </p>
-        </td>
-    {% endif %}
-
-    {% set color_background = 1 %}
-    {% set last_classes = "" %}
-
-    {% for sub in sub_table %}
-
-        {#  Color groups of classes in grey/white #}
-        {% if last_classes != sub.classes %}
-            {% if color_background %}{% set color_background = 0 %}
-                {% else %}{% set color_background = 1 %}
-            {% endif %}
+
+    <table class="substitutions">
+        <thead>
+        <tr>
+            <th><i class="material-icons">people</i></th>
+            <th><i class="material-icons">access_time</i></th>
+            <th>Lehrer</th>
+            <th>Fach</th>
+            <th>Raum</th>
+            <th>Hinweis</th>
+            <th></th>
+        </tr>
+        </thead>
+        <tbody>
+        {% if not c.sub_table %}
+            <td colspan="7">
+                <p class="flow-text center">
+                    Keine Vertretungen vorhanden
+                </p>
+            </td>
         {% endif %}
-        {% set last_classes = sub.classes %}
 
+        {% set color_background = 1 %}
+        {% set last_classes = "" %}
 
-        <tr class="{{ sub.color }}-text {% if color_background %}striped{% endif %}">
-            <td>
-                {{ sub.classes }}
-            </td>
-            <td>
-                <strong>
-                    {{ sub.lesson }}
-                </strong>
-            </td>
-            <td>
-                {% include "timetable/subs/teacher.html" %}
-            </td>
-            <td>
-                {% include "timetable/subs/subject.html" %}
-            </td>
-            <td>
-                {% include "timetable/subs/room.html" %}
-            </td>
-            <td>
-                {% if sub.badge %}
-                    <span class="badge new green">{{ sub.badge }}</span>
+        {% for sub in c.sub_table %}
+
+            {#  Color groups of classes in grey/white #}
+            {% if last_classes != sub.classes %}
+                {% if color_background %}{% set color_background = 0 %}
+                    {% else %}{% set color_background = 1 %}
                 {% endif %}
-                <em>{{ sub.text|default:"" }}</em>
-            </td>
-        </tr>
-    {% endfor %}
-    </tbody>
-</table>
+            {% endif %}
+            {% set last_classes = sub.classes %}
+
+
+            <tr class="{{ sub.color }}-text {% if color_background %}striped{% endif %}">
+                <td>
+                    {{ sub.classes }}
+                </td>
+                <td>
+                    <strong>
+                        {{ sub.lesson }}
+                    </strong>
+                </td>
+                <td>
+                    {% include "timetable/subs/teacher.html" %}
+                </td>
+                <td>
+                    {% include "timetable/subs/subject.html" %}
+                </td>
+                <td>
+                    {% include "timetable/subs/room.html" %}
+                </td>
+                <td>
+                    {% if sub.badge %}
+                        <span class="badge new green">{{ sub.badge }}</span>
+                    {% endif %}
+                    <em>{{ sub.text|default:"" }}</em>
+                </td>
+            </tr>
+        {% endfor %}
+        </tbody>
+    </table>
+
+{% endfor %}
 
 
 {% include 'partials/paper/footer.html' %}
diff --git a/biscuit/apps/chronos/urls.py b/biscuit/apps/chronos/urls.py
index 48106279..30dfa2fc 100755
--- a/biscuit/apps/chronos/urls.py
+++ b/biscuit/apps/chronos/urls.py
@@ -23,9 +23,9 @@ try:
         path('substitutions/', views.substitutions, name='timetable_substitutions'),
         path('substitutions/<int:year>/<int:month>/<int:day>/', views.substitutions,
              name='timetable_substitutions_date'),
-        path('substitutions/<int:year>/<int:month>/<int:day>/<str:print_view>/', views.substitutions,
+        path('substitutions/<int:year>/<int:month>/<int:day>/print/', views.substitutions_print,
              name='timetable_substitutions_date_print'),
-        path('substitutions/<str:print_view>/', views.substitutions,
+        path('substitutions/print/', views.substitutions_print,
              name='timetable_substitutions_print'),
         path('aktuell.pdf', views.sub_pdf, name="timetable_substitutions_pdf"),
         path('<str:plan_date>-aktuell.pdf', views.sub_pdf, name="timetable_substitutions_pdf_date")
diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py
index 1973b77c..16d7ef2d 100755
--- a/biscuit/apps/chronos/views.py
+++ b/biscuit/apps/chronos/views.py
@@ -328,21 +328,7 @@ def sub_pdf(request, plan_date=None):
     return FileResponse(file, content_type="application/pdf")
 
 
-@login_required
-@permission_required("timetable.show_plan")
-@cache_page(SUBS_VIEW_CACHE.expiration_time)
-def substitutions(request, year=None, month=None, day=None, print_view: str = False):
-    """Show substitutions in a classic view"""
-
-    print_view = print_view == "print"
-
-    date, time = find_out_what_is_today(year, month, day)
-
-    # Get next weekday if it is a weekend
-    next_weekday = get_next_weekday_with_time(date, time)
-    if next_weekday != date:
-        return redirect("timetable_substitutions_date", next_weekday.year, next_weekday.month, next_weekday.day)
-
+def get_subs_context(request, date):
     # Get subs and generate table
     events = get_all_events_by_date(date)
     subs = get_substitutions_by_date(date)
@@ -356,7 +342,7 @@ def substitutions(request, year=None, month=None, day=None, print_view: str = Fa
     header_info = get_header_information(subs, date, events)
     hints = list(get_all_hints_by_time_period(date, date))
 
-    context = {
+    return {
         "subs": subs,
         "sub_table": sub_table,
         "date": date,
@@ -365,10 +351,49 @@ def substitutions(request, year=None, month=None, day=None, print_view: str = Fa
         "hints": hints,
     }
 
-    if not print_view:
-        template_name = 'timetable/substitution.html'
-    else:
-        template_name = 'timetable/substitutionprint.html'
+
+@login_required
+@permission_required("timetable.show_plan")
+@cache_page(SUBS_VIEW_CACHE.expiration_time)
+def substitutions(request, year=None, month=None, day=None):
+    """Show substitutions in a classic view"""
+
+    date, time = find_out_what_is_today(year, month, day)
+
+    # Get next weekday if it is a weekend
+    next_weekday = get_next_weekday_with_time(date, time)
+    if next_weekday != date:
+        return redirect("timetable_substitutions_date", next_weekday.year, next_weekday.month, next_weekday.day)
+
+    context = get_subs_context(request, date)
+
+    template_name = 'timetable/substitution.html'
+
+    return render(request, template_name, context)
+
+
+@login_required
+@permission_required("timetable.show_plan")
+@cache_page(SUBS_VIEW_CACHE.expiration_time)
+def substitutions_print(request, year=None, month=None, day=None):
+    """Show substitutions in a classic view"""
+
+    date, time = find_out_what_is_today(year, month, day)
+
+    # Get next weekday if it is a weekend
+    next_weekday = get_next_weekday_with_time(date, time)
+    if next_weekday != date:
+        return redirect("timetable_substitutions_date_print", next_weekday.year, next_weekday.month, next_weekday.day)
+
+    second_date = get_next_weekday(date + datetime.timedelta(days=1))
+    context1 = get_subs_context(request, date)
+    context2 = get_subs_context(request, second_date)
+
+    context = {
+        "days": [context1, context2]
+    }
+
+    template_name = 'timetable/substitutionprint.html'
 
     return render(request, template_name, context)
 
-- 
GitLab