From 1f889be07aa5d5b04fdd02dde612c00ed6da2e91 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 27 Sep 2017 13:15:18 +0200 Subject: [PATCH] Refactor and add signal layout_text_variables --- doc/development/api/general.rst | 6 + src/pretix/plugins/ticketoutputpdf/signals.py | 21 +- .../pretixplugins/ticketoutputpdf/editor.js | 28 +-- .../pretixplugins/ticketoutputpdf/index.html | 24 +-- .../plugins/ticketoutputpdf/ticketoutput.py | 191 +++++++++++++----- src/pretix/plugins/ticketoutputpdf/views.py | 3 +- .../static/pretixcontrol/scss/_forms.scss | 7 + 7 files changed, 177 insertions(+), 103 deletions(-) diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index 800c97096..caae7ffee 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -64,3 +64,9 @@ Dashboards .. automodule:: pretix.control.signals :members: event_dashboard_widgets, user_dashboard_widgets + +Ticket designs +"""""""""""""" + +.. automodule:: pretix.plugins.ticketoutputpdf.signals + :members: layout_text_variables diff --git a/src/pretix/plugins/ticketoutputpdf/signals.py b/src/pretix/plugins/ticketoutputpdf/signals.py index 3cd8af5e7..b37f86cdf 100644 --- a/src/pretix/plugins/ticketoutputpdf/signals.py +++ b/src/pretix/plugins/ticketoutputpdf/signals.py @@ -3,7 +3,7 @@ from django.template.loader import get_template from django.urls import resolve from pretix.base.signals import ( - register_data_exporters, register_ticket_outputs, + EventPluginSignal, register_data_exporters, register_ticket_outputs, ) from pretix.control.signals import html_head from pretix.presale.style import ( # NOQA: legacy import @@ -33,3 +33,22 @@ def html_head_presale(sender, request=None, **kwargs): }) else: return "" + + +layout_text_variables = EventPluginSignal() +""" +This signal is sent out to collect variables that can be used to display text in PDF ticket layouts. +Receivers are expected to return a dictionary with globally unique identifiers as keys and more +dictionaries as values that contain keys like in the following example:: + + return { + "product": { + "label": _("Product name"), + "editor_sample": _("Sample product"), + "evaluate": lambda orderposition, order, event: str(orderposition.item) + } + } + +The evaluate member will be called with the order position, order and event as arguments. The event might +also be a subevent, if applicable. +""" diff --git a/src/pretix/plugins/ticketoutputpdf/static/pretixplugins/ticketoutputpdf/editor.js b/src/pretix/plugins/ticketoutputpdf/static/pretixplugins/ticketoutputpdf/editor.js index da431a5ff..c1cc5c97f 100644 --- a/src/pretix/plugins/ticketoutputpdf/static/pretixplugins/ticketoutputpdf/editor.js +++ b/src/pretix/plugins/ticketoutputpdf/static/pretixplugins/ticketoutputpdf/editor.js @@ -158,35 +158,11 @@ var editor = { editor._update_toolbox_values(); }, - text_samples: { - "secret": "tdmruoekvkpbv1o2mv8xccvqcikvr58u", - "order": "A1B2C", - "item": gettext("Sample product"), - "variation": gettext("Sample variation"), - "itemvar": gettext("Sample product – sample variation"), - "item_description": gettext("Sample product description"), - "price": gettext("123.45 EUR"), - "attendee_name": gettext("John Doe"), - "invoice_name": gettext("John Doe"), - "invoice_company": gettext("Sample company"), - "event_name": gettext("Sample event name"), - "event_date": gettext("May 31st, 2017"), - "event_date_range": gettext("May 31st – June 4th, 2017"), - "event_begin_time": gettext("20:00"), - "event_admission_time": gettext("19:00"), - "event_begin": gettext("2017-05-31 20:00"), - "event_admission": gettext("2017-05-31 19:00"), - "event_location": gettext("Random City"), - "organizer": gettext("Event organizer company"), - "organizer_info_text": gettext("Event organizer info text"), - "addons": gettext("Addon 1\nAddon 2"), - }, - _get_text_sample: function (key) { if (key.startsWith('meta:')) { return key.substr(5); } - return editor.text_samples[key]; + return $('#toolbox-content option[value='+key+']').attr('data-sample'); }, _load_pdf: function (dump) { @@ -406,7 +382,7 @@ var editor = { }, _add_text: function () { - var text = new fabric.Textarea(editor.text_samples['item'], { + var text = new fabric.Textarea(editor._get_text_sample('item'), { left: 100, top: 100, width: editor._mm2px(50), diff --git a/src/pretix/plugins/ticketoutputpdf/templates/pretixplugins/ticketoutputpdf/index.html b/src/pretix/plugins/ticketoutputpdf/templates/pretixplugins/ticketoutputpdf/index.html index fc45a5142..64aff7ec1 100644 --- a/src/pretix/plugins/ticketoutputpdf/templates/pretixplugins/ticketoutputpdf/index.html +++ b/src/pretix/plugins/ticketoutputpdf/templates/pretixplugins/ticketoutputpdf/index.html @@ -279,27 +279,9 @@