mirror of
https://github.com/pretix/pretix.git
synced 2026-08-12 11:07:02 +00:00
Add templatetag
This commit is contained in:
@@ -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 <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 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"<time datetime='{date_iso}'>{date_human}</time>"
|
||||
except AttributeError:
|
||||
return ''
|
||||
@@ -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 %}
|
||||
<span class="fa fa-ticket" aria-hidden="true"></span>
|
||||
{% 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="<time datetime='"|add:date_iso|add:"'>"|add:date_human|add:"</time>"|safe %}
|
||||
{% blocktrans with start_date=event.event.effective_presale_start|html_datetime:"SHORT_DATE_FORMAT"|safe %}
|
||||
from {{ start_date }}
|
||||
{% endblocktrans %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Soon" %}
|
||||
{% endif %}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{% load html_datetime %}
|
||||
{% load i18n %}
|
||||
{% load eventurl %}
|
||||
<div class="day-calendar cal-size-{{ raster_to_shortest_ratio }}{% if no_headlines %} no-headlines{% endif %}"
|
||||
@@ -116,7 +117,7 @@
|
||||
<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Sale over" %}
|
||||
{% 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.effective_presale_start|date:"SHORT_DATE_FORMAT" %}
|
||||
{% blocktrans with start_date=event.event.effective_presale_start|html_datetime:"SHORT_DATE_FORMAT"|safe %}
|
||||
from {{ start_date }}
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{% load html_datetime %}
|
||||
{% load i18n %}
|
||||
{% load date_fast %}
|
||||
<div class="week-calendar">
|
||||
@@ -79,7 +80,7 @@
|
||||
{% trans "Sale over" %}
|
||||
{% 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.effective_presale_start|date_fast:"SHORT_DATE_FORMAT" %}
|
||||
{% blocktrans with start_date=event.event.effective_presale_start|html_datetime:"SHORT_DATE_FORMAT"|safe %}
|
||||
from {{ start_date }}
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user