Add signal item_description

This commit is contained in:
Raphael Michel
2019-11-26 16:36:25 +01:00
parent 436dcc68f2
commit 14575693b8
3 changed files with 21 additions and 1 deletions

View File

@@ -26,7 +26,7 @@ Frontend
-------- --------
.. automodule:: pretix.presale.signals .. automodule:: pretix.presale.signals
:members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, fee_calculation_for_cart, contact_form_fields, question_form_fields, checkout_confirm_messages, checkout_confirm_page_content, checkout_all_optional, html_page_header, sass_preamble, sass_postamble, render_seating_plan, checkout_flow_steps, position_info :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, fee_calculation_for_cart, contact_form_fields, question_form_fields, checkout_confirm_messages, checkout_confirm_page_content, checkout_all_optional, html_page_header, sass_preamble, sass_postamble, render_seating_plan, checkout_flow_steps, position_info, item_description
.. automodule:: pretix.presale.signals .. automodule:: pretix.presale.signals

View File

@@ -256,3 +256,12 @@ invoice address, confirmations) will be optional, except for questions. Use with
As with all plugin signals, the ``sender`` keyword argument will contain the event. A ``request`` As with all plugin signals, the ``sender`` keyword argument will contain the event. A ``request``
argument will contain the request object. argument will contain the request object.
""" """
item_description = EventPluginSignal(
providing_args=["item", "variation"]
)
"""
This signal is sent out when the description of an item or variation is rendered and allows you to append
additional text to the description. You are passed the ``item`` and ``variation`` and expected to return
HTML.
"""

View File

@@ -22,6 +22,7 @@ from pretix.base.models.event import SubEvent
from pretix.base.models.items import ItemBundle from pretix.base.models.items import ItemBundle
from pretix.multidomain.urlreverse import eventreverse from pretix.multidomain.urlreverse import eventreverse
from pretix.presale.ical import get_ical from pretix.presale.ical import get_ical
from pretix.presale.signals import item_description
from pretix.presale.views.organizer import ( from pretix.presale.views.organizer import (
EventListMixin, add_subevents_for_days, filter_qs_by_attr, EventListMixin, add_subevents_for_days, filter_qs_by_attr,
weeks_for_template, weeks_for_template,
@@ -126,6 +127,11 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web', require
item._remove = True item._remove = True
continue continue
item.description = str(item.description)
for recv, resp in item_description.send(sender=event, item=item, variation=None):
if resp:
item.description += ("<br/>" if item.description else "") + resp
if not item.has_variations: if not item.has_variations:
item._remove = False item._remove = False
if not bool(item._subevent_quotas): if not bool(item._subevent_quotas):
@@ -171,6 +177,11 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web', require
display_add_to_cart = display_add_to_cart or item.order_max > 0 display_add_to_cart = display_add_to_cart or item.order_max > 0
else: else:
for var in item.available_variations: for var in item.available_variations:
var.description = str(var.description)
for recv, resp in item_description.send(sender=event, item=item, variation=var):
if resp:
var.description += ("<br/>" if var.description else "") + resp
if voucher and (voucher.allow_ignore_quota or voucher.block_quota): if voucher and (voucher.allow_ignore_quota or voucher.block_quota):
var.cached_availability = ( var.cached_availability = (
Quota.AVAILABILITY_OK, voucher.max_usages - voucher.redeemed Quota.AVAILABILITY_OK, voucher.max_usages - voucher.redeemed