From c8cb7a503d3451ebc6c30e5a21be648bc1ac7379 Mon Sep 17 00:00:00 2001 From: Phin Wolkwitz Date: Wed, 10 Dec 2025 15:13:11 +0100 Subject: [PATCH] Add templatetag --- src/pretix/base/templatetags/html_datetime.py | 43 +++++++++++++++++++ .../pretixpresale/fragment_calendar.html | 5 +-- .../pretixpresale/fragment_day_calendar.html | 3 +- .../pretixpresale/fragment_week_calendar.html | 3 +- src/pretix/presale/views/widget.py | 5 ++- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 src/pretix/base/templatetags/html_datetime.py diff --git a/src/pretix/base/templatetags/html_datetime.py b/src/pretix/base/templatetags/html_datetime.py new file mode 100644 index 0000000000..25b2d86c4d --- /dev/null +++ b/src/pretix/base/templatetags/html_datetime.py @@ -0,0 +1,43 @@ +# +# This file is part of pretix (Community Edition). +# +# Copyright (C) 2014-2020 Raphael Michel and contributors +# Copyright (C) 2020-today pretix 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 +from django.utils import dateformat +from django.utils.formats import get_format +from django.utils.translation import get_language + +register = template.Library() + + +@register.filter(expects_localtime=True, is_safe=False) +def html_datetime(value, arg=None): + if value in (None, ''): + return '' + + lang = get_language() + datetime_format = get_format(arg, lang) + + try: + date_iso = value.isoformat() + date_human = dateformat.format(value, datetime_format) + return f"" + except AttributeError: + return '' diff --git a/src/pretix/presale/templates/pretixpresale/fragment_calendar.html b/src/pretix/presale/templates/pretixpresale/fragment_calendar.html index 8a7b74ad22..1ac3ffcbba 100644 --- a/src/pretix/presale/templates/pretixpresale/fragment_calendar.html +++ b/src/pretix/presale/templates/pretixpresale/fragment_calendar.html @@ -1,3 +1,4 @@ +{% load html_datetime %} {% load i18n %} {% load date_fast %} {% load calendarhead %} @@ -110,11 +111,9 @@ {% trans "Sale over" %} {% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %} - {% with date_human=event.event.effective_presale_start|date_fast:"SHORT_DATE_FORMAT" date_iso=event.event.effective_presale_start|date_fast:"c" %} - {% blocktrans with start_date=""|safe %} + {% blocktrans with start_date=event.event.effective_presale_start|html_datetime:"SHORT_DATE_FORMAT"|safe %} from {{ start_date }} {% endblocktrans %} - {% endwith %} {% else %} {% trans "Soon" %} {% endif %} diff --git a/src/pretix/presale/templates/pretixpresale/fragment_day_calendar.html b/src/pretix/presale/templates/pretixpresale/fragment_day_calendar.html index ab2c6f168a..815aa1b779 100644 --- a/src/pretix/presale/templates/pretixpresale/fragment_day_calendar.html +++ b/src/pretix/presale/templates/pretixpresale/fragment_day_calendar.html @@ -1,3 +1,4 @@ +{% load html_datetime %} {% load i18n %} {% load eventurl %}