Fix presale date display in calendar (Z#23216645) (#5710)

Fix presale date display in calendar and introduce a template tag
This commit is contained in:
Phin Wolkwitz
2025-12-17 16:18:59 +01:00
committed by GitHub
parent 2e89fc0a94
commit 11df4398e1
8 changed files with 106 additions and 39 deletions

View File

@@ -0,0 +1,65 @@
#
# 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 <https://pretix.eu/about/en/license>.
#
# 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
# <https://www.gnu.org/licenses/>.
#
from datetime import datetime
from django import template
from django.utils.html import format_html
from django.utils.timezone import get_current_timezone
from pretix.base.i18n import LazyExpiresDate
from pretix.helpers.templatetags.date_fast import date_fast
register = template.Library()
@register.simple_tag
def html_time(value: datetime, dt_format: str = "SHORT_DATE_FORMAT", **kwargs):
"""
Building a <time datetime='{html-datetime}'>{human-readable datetime}</time> html string,
where the html-datetime as well as the human-readable datetime can be set
to a value from django's FORMAT_SETTINGS or "format_expires".
If attr_fmt isnt provided, it will be set to isoformat.
Usage example:
{% html_time event_start "SHORT_DATETIME_FORMAT" %}
or
{% html_time event_start "TIME_FORMAT" attr_fmt="H:i" %}
"""
if value in (None, ''):
return ''
value = value.astimezone(get_current_timezone())
attr_fmt = kwargs["attr_fmt"] if kwargs else None
try:
if not attr_fmt:
date_html = value.isoformat()
else:
date_html = date_fast(value, attr_fmt)
if dt_format == "format_expires":
date_human = LazyExpiresDate(value)
else:
date_human = date_fast(value, dt_format)
return format_html("<time datetime='{}'>{}</time>", date_html, date_human)
except AttributeError:
return ''

View File

@@ -1,3 +1,4 @@
{% load html_time %}
{% load i18n %}
{% load icon %}
{% load eventurl %}
@@ -21,20 +22,18 @@
{% if event.settings.show_times %}
<br>
<span data-time="{{ ev.date_from.isoformat }}" data-timezone="{{ request.event.timezone }}">
{% with time_human=ev.date_from|date:"TIME_FORMAT" time_24=ev.date_from|time:"H:i" %}
{% blocktrans trimmed with time='<time datetime="'|add:time_24|add:'">'|add:time_human|add:"</time>"|safe %}
Begin: {{ time }}
{% endblocktrans %}
{% endwith %}
{% html_time ev.date_from "TIME_FORMAT" attr_fmt="H:i" as time%}
{% blocktrans with time=time %}
Begin: {{ time }}
{% endblocktrans %}
</span>
{% if event.settings.show_date_to and ev.date_to %}
<br>
<span data-time="{{ ev.date_to.isoformat }}" data-timezone="{{ request.event.timezone }}">
{% with time_human=ev.date_to|date:"TIME_FORMAT" time_24=ev.date_to|time:"H:i" %}
{% blocktrans trimmed with time='<time datetime="'|add:time_24|add:'">'|add:time_human|add:"</time>"|safe %}
End: {{ time }}
{% endblocktrans %}
{% endwith %}
{% html_time ev.date_to "TIME_FORMAT" attr_fmt="H:i" as time%}
{% blocktrans with time=time %}
End: {{ time }}
{% endblocktrans %}
</span>
{% endif %}
{% endif %}
@@ -42,19 +41,17 @@
<br>
{% if ev.date_admission|date:"SHORT_DATE_FORMAT" == ev.date_from|date:"SHORT_DATE_FORMAT" %}
<span data-time="{{ ev.date_admission.isoformat }}" data-timezone="{{ request.event.timezone }}">
{% with time_human=ev.date_admission|date:"TIME_FORMAT" time_24=ev.date_admission|time:"H:i" %}
{% blocktrans trimmed with time='<time datetime="'|add:time_24|add:'">'|add:time_human|add:"</time>"|safe %}
Admission: {{ time }}
{% endblocktrans %}
{% endwith %}
{% html_time ev.date_admission "TIME_FORMAT" attr_fmt="H:i" as time%}
{% blocktrans trimmed with time=time %}
Admission: {{ time }}
{% endblocktrans %}
</span>
{% else %}
<span data-time="{{ ev.date_admission.isoformat }}" data-timezone="{{ request.event.timezone }}">
{% with datetime_human=ev.date_admission|date:"SHORT_DATETIME_FORMAT" datetime_iso=ev.date_admission|time:"Y-m-d H:i" %}
{% blocktrans trimmed with datetime='<time datetime="'|add:datetime_iso|add:'">'|add:datetime_human|add:"</time>"|safe %}
Admission: {{ datetime }}
{% endblocktrans %}
{% endwith %}
{% html_time ev.date_admission "SHORT_DATETIME_FORMAT" attr_fmt="Y-m-d H:i" as datetime%}
{% blocktrans trimmed with datetime=datetime %}
Admission: {{ datetime }}
{% endblocktrans %}
</span>
{% endif %}
{% endif %}

View File

@@ -1,4 +1,5 @@
{% extends "pretixpresale/event/base.html" %}
{% load html_time %}
{% load i18n %}
{% load bootstrap3 %}
{% load eventsignal %}
@@ -92,11 +93,10 @@
A payment of {{ total }} is still pending for this order.
{% endblocktrans %}</strong>
<strong>
{% with date_human=order|format_expires|safe date_iso=order.expires|date:"c" %}
{% blocktrans trimmed with date='<time datetime="'|add:date_iso|add:'">'|add:date_human|add:"</time>"|safe %}
{% html_time order.expires "format_expires" as date %}
{% blocktrans trimmed with date=date %}
Please complete your payment before {{ date }}
{% endblocktrans %}
{% endwith %}
</strong>
</p>
{% if last_payment %}

View File

@@ -1,3 +1,4 @@
{% load html_time %}
{% load i18n %}
{% load date_fast %}
{% load calendarhead %}
@@ -55,7 +56,7 @@
running
{% elif event.event.presale_has_ended %}
over
{% elif event.event.settings.presale_start_show_date and event.event.presale_start %}
{% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %}
soon
{% else %}
soon
@@ -108,13 +109,12 @@
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Book now" %}
{% elif event.event.presale_has_ended %}
{% trans "Sale over" %}
{% elif event.event.settings.presale_start_show_date and event.event.presale_start %}
{% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %}
<span class="fa fa-ticket" aria-hidden="true"></span>
{% with date_human=event.event.presale_start|date_fast:"SHORT_DATE_FORMAT" date_iso=event.event.presale_start|date_fast:"c" %}
{% blocktrans with start_date="<time datetime='"|add:date_iso|add:"'>"|add:date_human|add:"</time>"|safe %}
{% html_time event.event.effective_presale_start "SHORT_DATE_FORMAT" as start_date %}
{% blocktrans with start_date=start_date %}
from {{ start_date }}
{% endblocktrans %}
{% endwith %}
{% else %}
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Soon" %}
{% endif %}

View File

@@ -1,3 +1,4 @@
{% load html_time %}
{% load i18n %}
{% load eventurl %}
<div class="day-calendar cal-size-{{ raster_to_shortest_ratio }}{% if no_headlines %} no-headlines{% endif %}"
@@ -52,7 +53,7 @@
running
{% elif event.event.presale_has_ended %}
over
{% elif event.event.settings.presale_start_show_date and event.event.presale_start %}
{% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %}
soon
{% else %}
soon
@@ -114,9 +115,10 @@
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Book now" %}
{% elif event.event.presale_has_ended %}
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Sale over" %}
{% elif event.event.settings.presale_start_show_date and event.event.presale_start %}
{% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %}
<span class="fa fa-ticket" aria-hidden="true"></span>
{% blocktrans with start_date=event.event.presale_start|date:"SHORT_DATE_FORMAT" %}
{% html_time event.event.effective_presale_start "SHORT_DATE_FORMAT" as start_date %}
{% blocktrans with start_date=start_date %}
from {{ start_date }}
{% endblocktrans %}
{% else %}

View File

@@ -1,3 +1,4 @@
{% load html_time %}
{% load i18n %}
{% load icon %}
{% load textbubble %}
@@ -52,11 +53,10 @@
{% endtextbubble %}
{% if event.settings.presale_start_show_date %}
<br><span class="text-muted">
{% with date_iso=event.effective_presale_start.isoformat date_human=event.effective_presale_start|date:"SHORT_DATE_FORMAT" %}
{% blocktrans trimmed with date='<time datetime="'|add:date_iso|add:'">'|add:date_human|add:"</time>"|safe %}
{% html_time event.event.effective_presale_start "SHORT_DATE_FORMAT" as date %}
{% blocktrans with date=date %}
Sale starts {{ date }}
{% endblocktrans %}
{% endwith %}
</span>
{% endif %}
{% endif %}

View File

@@ -1,3 +1,4 @@
{% load html_time %}
{% load i18n %}
{% load date_fast %}
<div class="week-calendar">
@@ -24,7 +25,7 @@
running
{% elif event.event.presale_has_ended %}
over
{% elif event.event.settings.presale_start_show_date and event.event.presale_start %}
{% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %}
soon
{% else %}
soon
@@ -77,9 +78,10 @@
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Book now" %}
{% elif event.event.presale_has_ended %}
{% trans "Sale over" %}
{% elif event.event.settings.presale_start_show_date and event.event.presale_start %}
{% elif event.event.settings.presale_start_show_date and event.event.effective_presale_start %}
<span class="fa fa-ticket" aria-hidden="true"></span>
{% blocktrans with start_date=event.event.presale_start|date_fast:"SHORT_DATE_FORMAT" %}
{% html_time event.event.effective_presale_start "SHORT_DATE_FORMAT" as start_date %}
{% blocktrans with start_date=start_date %}
from {{ start_date }}
{% endblocktrans %}
{% else %}

View File

@@ -471,10 +471,11 @@ class WidgetAPIProductList(EventListMixin, View):
availability['color'] = 'red'
availability['text'] = gettext('Sale over')
availability['reason'] = 'over'
elif event.settings.presale_start_show_date and ev.presale_start:
elif event.settings.presale_start_show_date and ev.effective_presale_start:
availability['color'] = 'orange'
availability['text'] = gettext('from %(start_date)s') % {
'start_date': date_format(ev.presale_start.astimezone(tz or event.timezone), "SHORT_DATE_FORMAT")
'start_date': date_format(ev.effective_presale_start.astimezone(tz or event.timezone),
"SHORT_DATE_FORMAT")
}
availability['reason'] = 'soon'
else: