diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index edb2deef9..d28dec001 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -78,3 +78,6 @@ Ticket designs .. automodule:: pretix.base.signals :members: layout_text_variables + +.. automodule:: pretix.plugins.ticketoutputpdf.signals + :members: override_layout diff --git a/src/pretix/plugins/ticketoutputpdf/signals.py b/src/pretix/plugins/ticketoutputpdf/signals.py index 1ed475692..df0e3c03c 100644 --- a/src/pretix/plugins/ticketoutputpdf/signals.py +++ b/src/pretix/plugins/ticketoutputpdf/signals.py @@ -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'] = '{val}'.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. +""" diff --git a/src/pretix/plugins/ticketoutputpdf/ticketoutput.py b/src/pretix/plugins/ticketoutputpdf/ticketoutput.py index c72d0cd20..e2dad709d 100644 --- a/src/pretix/plugins/ticketoutputpdf/ticketoutput.py +++ b/src/pretix/plugins/ticketoutputpdf/ticketoutput.py @@ -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):