From 1b3f27852d6a58511e34df80aab88d24940dcc5c Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 29 Jan 2024 13:32:36 +0100 Subject: [PATCH] Calendar: Fix week day header for incomplete months --- src/pretix/base/templatetags/calendarhead.py | 34 +++++++++++++++++++ .../pretixpresale/fragment_calendar.html | 11 +++--- src/pretix/presale/views/event.py | 1 + 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/pretix/base/templatetags/calendarhead.py diff --git a/src/pretix/base/templatetags/calendarhead.py b/src/pretix/base/templatetags/calendarhead.py new file mode 100644 index 000000000..912e2a600 --- /dev/null +++ b/src/pretix/base/templatetags/calendarhead.py @@ -0,0 +1,34 @@ +# +# This file is part of pretix (Community Edition). +# +# Copyright (C) 2014-2020 Raphael Michel and contributors +# Copyright (C) 2020-2021 rami.io GmbH and contributors +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General +# Public License as published by the Free Software Foundation in version 3 of the License. +# +# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are +# applicable granting you additional permissions and placing additional restrictions on your usage of this software. +# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive +# this file, see . +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along with this program. If not, see +# . +# + +from django import template + +register = template.Library() + + +@register.filter("iter_weekdays") +def iter_weekdays(weeks): + for i in range(7): + for w in weeks: + if i <= len(w) and w[i]: + yield w[i]['date'] + break diff --git a/src/pretix/presale/templates/pretixpresale/fragment_calendar.html b/src/pretix/presale/templates/pretixpresale/fragment_calendar.html index 019f59830..25d7dbd99 100644 --- a/src/pretix/presale/templates/pretixpresale/fragment_calendar.html +++ b/src/pretix/presale/templates/pretixpresale/fragment_calendar.html @@ -1,17 +1,14 @@ {% load i18n %} {% load date_fast %} +{% load calendarhead %}
- - - - - - - + {% for d in weeks|iter_weekdays %} + + {% endfor %} diff --git a/src/pretix/presale/views/event.py b/src/pretix/presale/views/event.py index 5e0162937..848bf0e3f 100644 --- a/src/pretix/presale/views/event.py +++ b/src/pretix/presale/views/event.py @@ -679,6 +679,7 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView): timeout=120, ) context['weeks'] = weeks_for_template(ebd, self.year, self.month, future_only=self.request.event.settings.event_calendar_future_only) + context['weeks'] = weeks_for_template(ebd, self.year, self.month, future_only=self.request.event.settings.event_calendar_future_only) context['months'] = [date(self.year, i + 1, 1) for i in range(12)] if self.request.event.settings.event_calendar_future_only: context['years'] = range(now().year, now().year + 3)
{% trans "Calendar" %}
{{ weeks.1.0.date|date_fast:"l" }}{{ weeks.1.1.date|date_fast:"l" }}{{ weeks.1.2.date|date_fast:"l" }}{{ weeks.1.3.date|date_fast:"l" }}{{ weeks.1.4.date|date_fast:"l" }}{{ weeks.1.5.date|date_fast:"l" }}{{ weeks.1.6.date|date_fast:"l" }}{{ d|date_fast:"l" }}