diff --git a/calendar_utils/models.py b/calendar_utils/models.py index 2156b53903eb67af0a99a8c7ceec43750cfb4116..807b73f1ae4fe6752b90977c3be55712ba522d9e 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/calendar_utils/templatetags/event_list.py b/calendar_utils/templatetags/event_list.py new file mode 100644 index 0000000000000000000000000000000000000000..1e20ba040004f5afe6af5bdb21637397773b77d6 --- /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 9f14489f16e8b7ca65e5309305aed5b6d4fd22a3..bb7c591b6092473a1b99f76f174c2deb60bca731 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 da8181a21fac479979c97ad06b1984c3ca7e6018..36dcbf5dad1b489fc9abbfc346372507de664a78 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 %}