diff --git a/calendar_utils/models.py b/calendar_utils/models.py index a39a5fba99dbb7b9e9562728cc7f841bbaf2a91f..9c407010ddd4ceabef16d5da5e6127da4151a66e 100644 --- a/calendar_utils/models.py +++ b/calendar_utils/models.py @@ -90,6 +90,10 @@ class CalendarMixin(models.Model): blank=True, ) + @property + def first_calendar_page(self): + return self._first_subpage_of_type(CalendarPage) + class Meta: abstract = True @@ -154,8 +158,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 71fef1f7878d86be9ff010e4eb09d5bb0474adef..e8319841f6f7b6f3dc97029cab6548263f1408ef 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 0c95f7e733be84431fcc09f2fcb3cda108d920d8..2475677f03d59d4f87d343389a34496b9dec40b3 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> @@ -51,6 +57,8 @@ <p>Žádné události.</p> </div> {% endfor %} + {% endwith %} + {% endwith %} </div> </div> {% else %}