From bf48f960dc96ec6c8fc8dce42612491ee07a5896 Mon Sep 17 00:00:00 2001 From: "jindra12.underdark" <jindra12.underdark@gmail.com> Date: Fri, 14 Apr 2023 20:44:45 +0200 Subject: [PATCH] Display all events if fullscreen #163 --- calendar_utils/models.py | 14 ++++++++++++-- calendar_utils/templatetags/__init__.py | 0 calendar_utils/templatetags/event_list.py | 14 ++++++++++++++ district/models.py | 2 +- .../calendar_current_events_snippet.html | 18 +++++++++++++----- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 calendar_utils/templatetags/__init__.py create mode 100644 calendar_utils/templatetags/event_list.py diff --git a/calendar_utils/models.py b/calendar_utils/models.py index 2156b539..807b73f1 100644 --- a/calendar_utils/models.py +++ b/calendar_utils/models.py @@ -99,6 +99,10 @@ class CalendarMixin(models.Model): blank=True, ) + @property + def first_calendar_page(self): + return self._first_subpage_of_type(CalendarPage) + class Meta: abstract = True @@ -195,8 +199,14 @@ class CalendarPage(SubpageMixin, MetadataPageMixin, CalendarMixin, Page): pathname = module.split(".")[0] # Gets "district" from "district.module" root = str(Path(__file__).parents[2]) project = root + "/majak" - return ( - project + "/" + pathname + "/templates/" + pathname + "_calendar_page.html" + return str( + Path( + project, + pathname, + "templates", + pathname, + pathname + "_calendar_page.html", + ) ) class Meta: diff --git a/calendar_utils/templatetags/__init__.py b/calendar_utils/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/calendar_utils/templatetags/event_list.py b/calendar_utils/templatetags/event_list.py new file mode 100644 index 00000000..1e20ba04 --- /dev/null +++ b/calendar_utils/templatetags/event_list.py @@ -0,0 +1,14 @@ +from django import template + +register = template.Library() + + +def event_list(calendar, full_list): + """ + Outputs a list of events, in case the calendar is on calendar page, it will print all future events, + otherwise will print only a fraction + """ + return calendar.future_events if full_list else calendar.current_events + + +register.filter("event_list", event_list) diff --git a/district/models.py b/district/models.py index 9f14489f..bb7c591b 100644 --- a/district/models.py +++ b/district/models.py @@ -26,7 +26,7 @@ from wagtail.fields import RichTextField, StreamField from wagtail.models import Orderable, Page from wagtailmetadata.models import MetadataPageMixin -from calendar_utils.models import CalendarMixin +from calendar_utils.models import CalendarMixin, CalendarPage from maps_utils.blocks import MapPointBlock from maps_utils.const import ( DEFAULT_MAP_STYLE, diff --git a/shared/templates/shared/calendar_current_events_snippet.html b/shared/templates/shared/calendar_current_events_snippet.html index da8181a2..36dcbf5d 100644 --- a/shared/templates/shared/calendar_current_events_snippet.html +++ b/shared/templates/shared/calendar_current_events_snippet.html @@ -1,18 +1,24 @@ +{% load event_list %} {% if page.root_page.has_calendar %} <div class="calendar grid grid-cols-4"> <div class="col-span-4 xl:col-span-1"> <aside class="banner bg-orange-300 text-white h-full"> <i class="ico--calendar banner__icon"></i> <div class="banner__body"><h1 class="head-alt-md banner__cta">Kalendář</h1> - <button class="btn btn--white btn--fullwidth sm:btn--autowidth mt-8"> - {{ event }} - <div class="btn__body">Zobrazit další</div> - </button> + {% if not fullscreen and page.root_page.first_calendar_page %} + <a href="{{ page.root_page.first_calendar_page.url }}"> + <button class="btn btn--white btn--fullwidth sm:btn--autowidth mt-8"> + <div class="btn__body">Zobrazit další</div> + </button> + </a> + {% endif %} </div> </aside> </div> <div class="col-span-4 xl:col-span-3"> - {% for event in page.root_page.calendar.current_events %} + {% with full_list=fullscreen %} + {% with events=page.root_page.calendar|event_list:full_list %} + {% for event in events %} <div class="grid grid-cols-12 items-center calendar-table-row"> <div class="col-span-2 text-orange-300 head-alt-md calendar-table-row__col"> <span>{{ event.start|date:"j." }}</span> @@ -62,6 +68,8 @@ <p>Žádné události.</p> </div> {% endfor %} + {% endwith %} + {% endwith %} </div> </div> {% else %} -- GitLab