forked from CGM_Public/pretix_original
Add event placeholder support to more fields (#6098)
* Add event placeholder support to more fields
I found it useful to be able to use the `{event}` placeholder in
some fields such as the "End of presale text" because I don't need
to fix the texts creating a new event by cloning another event.
I made placeholders available to the other fields as well (where not too
difficult). Specifically `presale_has_ended_text`, `voucher_explanation_text`
`banner_text`, `banner_text_bottom` and `event_info_text`.
In addition, I grouped them under a new `texts` variable in the `context`
(including `frontpage_text` which was part of the root `context` previously).
* change compute location
---------
Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
co-authored by
Raphael Michel
parent
fe0f7864e7
commit
617a548b19
+10
-5
@@ -77,6 +77,7 @@ from reportlab.platypus import Paragraph
|
||||
|
||||
from pretix.base.i18n import language
|
||||
from pretix.base.models import Checkin, Event, Order, OrderPosition, Question
|
||||
from pretix.base.services.placeholders import PlaceholderContext
|
||||
from pretix.base.settings import PERSON_NAME_SCHEMES
|
||||
from pretix.base.signals import layout_image_variables, layout_text_variables
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
@@ -401,11 +402,7 @@ DEFAULT_VARIABLES = OrderedDict((
|
||||
"editor_sample": _("Event organizer info text"),
|
||||
"evaluate": lambda op, order, ev: str(order.event.settings.organizer_info_text)
|
||||
}),
|
||||
("event_info_text", {
|
||||
"label": _("Event info text"),
|
||||
"editor_sample": _("Event info text"),
|
||||
"evaluate": lambda op, order, ev: str(order.event.settings.event_info_text)
|
||||
}),
|
||||
("event_info_text", {}), # Placeholder to "reserve" position, defined later in `get_variables`
|
||||
("now_date", {
|
||||
"label": _("Printing date"),
|
||||
"editor_sample": _("2017-05-31"),
|
||||
@@ -670,6 +667,14 @@ def get_images(event):
|
||||
def get_variables(event):
|
||||
v = copy.copy(DEFAULT_VARIABLES)
|
||||
|
||||
templating_context = PlaceholderContext(event=event)
|
||||
v['event_info_text'] = {
|
||||
"label": _("Event info text"),
|
||||
"editor_sample": _("Event info text"),
|
||||
"evaluate": lambda op, order, ev:
|
||||
templating_context.format(str(order.event.settings.event_info_text))
|
||||
}
|
||||
|
||||
scheme = PERSON_NAME_SCHEMES[event.settings.name_scheme]
|
||||
|
||||
concatenation_for_salutation = scheme.get("concatenation_for_salutation", scheme["concatenation"])
|
||||
|
||||
@@ -671,6 +671,11 @@ class EventSettingsForm(EventSettingsValidationMixin, FormPlaceholderMixin, Sett
|
||||
|
||||
base_context = {
|
||||
'frontpage_text': ['event'],
|
||||
'presale_has_ended_text': ['event'],
|
||||
'voucher_explanation_text': ['event'],
|
||||
'banner_text': ['event'],
|
||||
'banner_text_bottom': ['event'],
|
||||
'event_info_text': ['event'],
|
||||
}
|
||||
|
||||
def _resolve_virtual_keys_input(self, data, prefix=''):
|
||||
|
||||
@@ -46,6 +46,7 @@ from pretix.helpers.i18n import (
|
||||
)
|
||||
|
||||
from ..base.i18n import get_language_without_region
|
||||
from ..base.services.placeholders import PlaceholderContext
|
||||
from ..multidomain.urlreverse import eventreverse
|
||||
from .cookies import get_cookie_providers
|
||||
from .signals import (
|
||||
@@ -87,6 +88,12 @@ def _default_context(request):
|
||||
f'{request.event.cache.get_or_set("css_version", default=lambda: int(time.time()))}')
|
||||
ctx['css_theme'] = eventreverse(request.event, "presale:event.theme.css") + "?version=" + theme_css_version
|
||||
|
||||
templating_context = PlaceholderContext(event=request.event)
|
||||
ctx['event_texts'] = {
|
||||
field: templating_context.format(str(request.event.settings.get(field)))
|
||||
for field in ('banner_text', 'banner_text_bottom', 'voucher_explanation_text')
|
||||
}
|
||||
|
||||
elif hasattr(request, 'organizer') and request.organizer:
|
||||
pretix_settings = request.organizer.settings
|
||||
|
||||
|
||||
@@ -184,18 +184,18 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if request.event.settings.banner_text %}
|
||||
{% if event_texts.banner_text %}
|
||||
<div class="site-notice-top">
|
||||
{{ request.event.settings.banner_text|rich_text }}
|
||||
{{ event_texts.banner_text|rich_text }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
{% block footer %}
|
||||
{% if request.event.settings.banner_text_bottom %}
|
||||
{% if event_texts.banner_text_bottom %}
|
||||
<div class="site-notice-bottom">
|
||||
{{ request.event.settings.banner_text_bottom|rich_text }}
|
||||
{{ event_texts.banner_text_bottom|rich_text }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.event.testmode %}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{% load i18n %}
|
||||
{% load eventurl %}
|
||||
{% load rich_text %}
|
||||
{% if event.settings.voucher_explanation_text %}
|
||||
{% if event_texts.voucher_explanation_text %}
|
||||
<div>
|
||||
{{ event.settings.voucher_explanation_text|rich_text }}
|
||||
{{ event_texts.voucher_explanation_text|rich_text }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="get" action="{% eventurl event "presale:event.redeem" cart_namespace=cart_namespace %}">
|
||||
|
||||
@@ -151,8 +151,8 @@
|
||||
{% if not ev.presale_is_running %}
|
||||
<div class="alert alert-info">
|
||||
{% if ev.presale_has_ended %}
|
||||
{% if event.settings.presale_has_ended_text %}
|
||||
{{ event.settings.presale_has_ended_text|rich_text }}
|
||||
{% if presale_has_ended_text %}
|
||||
{{ presale_has_ended_text|rich_text }}
|
||||
{% else %}
|
||||
{% blocktrans trimmed %}
|
||||
The booking period for this event is over.
|
||||
|
||||
@@ -634,6 +634,10 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
|
||||
context['has_addon_choices'] = any(cp.has_addon_choices for cp in get_cart(self.request))
|
||||
|
||||
templating_context = PlaceholderContext(event_or_subevent=self.subevent or self.request.event, event=self.request.event)
|
||||
|
||||
for field in ('presale_has_ended_text',):
|
||||
context[field] = templating_context.format(str(self.request.event.settings[field]))
|
||||
|
||||
if self.subevent:
|
||||
context['frontpage_text'] = templating_context.format(str(self.subevent.frontpage_text))
|
||||
else:
|
||||
|
||||
@@ -834,7 +834,7 @@ class WidgetAPIProductList(EventListMixin, View):
|
||||
data['vouchers_exist'] = False
|
||||
if ev.presale_has_ended:
|
||||
if request.event.settings.presale_has_ended_text:
|
||||
data['error'] = str(request.event.settings.presale_has_ended_text)
|
||||
data['error'] = templating_context.format(str(request.event.settings.presale_has_ended_text))
|
||||
else:
|
||||
data['error'] = gettext('The booking period for this event is over.')
|
||||
elif request.event.settings.presale_start_show_date:
|
||||
|
||||
Reference in New Issue
Block a user