New signal: ticketoutput_override_layout (#1483)

* Add signal to override ticketoutput layout

* Change Signal collection to send_chained

* Move ticketoutput_override_layout to ticketoutputpdf-plugin
This commit is contained in:
Martin Gross
2019-11-15 11:18:52 +01:00
committed by Raphael Michel
parent a2c1c69d7e
commit 3b306de1bb
3 changed files with 36 additions and 12 deletions

View File

@@ -8,8 +8,9 @@ from django.utils.translation import ugettext_lazy as _
from pretix.base.channels import get_all_sales_channels
from pretix.base.signals import ( # NOQA: legacy import
event_copy_data, item_copy_data, layout_text_variables, logentry_display,
logentry_object_link, register_data_exporters, register_ticket_outputs,
EventPluginSignal, event_copy_data, item_copy_data, layout_text_variables,
logentry_display, logentry_object_link, register_data_exporters,
register_ticket_outputs,
)
from pretix.control.signals import item_forms
from pretix.plugins.ticketoutputpdf.forms import TicketLayoutItemForm
@@ -122,3 +123,17 @@ def pdf_logentry_object_link(sender, logentry, **kwargs):
}
a_map['val'] = '<a href="{href}">{val}</a>'.format_map(a_map)
return a_text.format_map(a_map)
override_layout = EventPluginSignal(
providing_args=["position", "layout"]
)
"""
This signal allows you to forcefully override the ticket layout that is being used to create the ticket PDF. Use with
care, as this will render any specifically by the organizer selected templates useless.
The ``position`` keyword argument will contain the ``OrderPosition`` which is being generated, the ``layout`` keyword
argument will contain the layout which has been originally selected by the system.
As with all plugin signals, the ``sender`` keyword will contain the event.
"""

View File

@@ -19,6 +19,7 @@ from pretix.base.ticketoutput import BaseTicketOutput
from pretix.plugins.ticketoutputpdf.models import (
TicketLayout, TicketLayoutItem,
)
from pretix.plugins.ticketoutputpdf.signals import override_layout
logger = logging.getLogger('pretix.plugins.ticketoutputpdf')
@@ -78,11 +79,13 @@ class PdfTicketOutput(BaseTicketOutput):
merger = PdfFileMerger()
with language(order.locale):
for op in order.positions_with_tickets:
layout = self.layout_map.get(
(op.item_id, order.sales_channel),
self.layout_map.get(
(op.item_id, 'web'),
self.default_layout
layout = override_layout.send_chained(
order.event, 'layoutoverride', orderposition=op, layout=self.layout_map.get(
(op.item_id, order.sales_channel),
self.layout_map.get(
(op.item_id, 'web'),
self.default_layout
)
)
)
outbuffer = self._draw_page(layout, op, order)
@@ -96,11 +99,14 @@ class PdfTicketOutput(BaseTicketOutput):
def generate(self, op):
order = op.order
layout = self.layout_map.get(
(op.item_id, order.sales_channel),
self.layout_map.get(
(op.item_id, 'web'),
self.default_layout
layout = override_layout.send_chained(
order.event, 'layoutoverride', orderposition=op, layout=self.layout_map.get(
(op.item_id, order.sales_channel),
self.layout_map.get(
(op.item_id, 'web'),
self.default_layout
)
)
)
with language(order.locale):