From 588a4aa3cc643673555752c106ca7fa78c4108e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Wed, 11 Aug 2021 21:17:19 +0200
Subject: [PATCH] elections2021: Fix calendar

---
 elections2021/models.py                        | 18 +++++-------------
 .../elections2021_calendar_page.html           |  2 +-
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/elections2021/models.py b/elections2021/models.py
index 55a34a63..60d9789d 100644
--- a/elections2021/models.py
+++ b/elections2021/models.py
@@ -383,7 +383,7 @@ class Elections2021HomePage(MetadataPageMixin, RoutablePageMixin, Page):
             .live()
             .specific()
             .first()
-            .calendar
+            .get_calendar()
         )
 
     @cached_property
@@ -2428,16 +2428,9 @@ class Elections2021CalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin,
     def has_calendar(self):
         return self.calendar_id is not None
 
-    def get_context(self, request):
-        context = super().get_context(request)
-
-        future_events = self.calendar.future_events
-        for event in future_events:
-            event["pir"] = {
-                "name": None,
-                "tags": [],
-                "region": None,
-            }
+    def get_calendar(self):
+        for event in self.calendar.future_events:
+            event["pir"] = {"name": None, "tags": [], "region": None}
 
             pir_name = []
 
@@ -2453,5 +2446,4 @@ class Elections2021CalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin,
 
             event["pir"]["name"] = " ".join(pir_name)
 
-        context["future_events"] = future_events
-        return context
+        return self.calendar
diff --git a/elections2021/templates/elections2021/elections2021_calendar_page.html b/elections2021/templates/elections2021/elections2021_calendar_page.html
index 56d8b84a..64901289 100644
--- a/elections2021/templates/elections2021/elections2021_calendar_page.html
+++ b/elections2021/templates/elections2021/elections2021_calendar_page.html
@@ -148,7 +148,7 @@
   </div>
 
 <div class="container container--default pt-8 pb-16 px-0 md:px-1">
-  {% for event in future_events %}
+  {% for event in page.get_calendar.future_events %}
     {% if not request.GET.tag or request.GET.tag in event.pir.tags %}
       {% if not request.GET.region or request.GET.region == event.pir.region %}
         <div class="grid grid-cols-12 items-center calendar-table-row my-1">
-- 
GitLab