From 07a11e4df27fdf4b3c598765cfae67a276ac9d4a Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 10 May 2021 18:43:46 +0200 Subject: [PATCH] Fix two different default ticket layouts in different places --- src/pretix/plugins/ticketoutputpdf/models.py | 370 +++++++++--------- .../plugins/ticketoutputpdf/ticketoutput.py | 31 +- 2 files changed, 188 insertions(+), 213 deletions(-) diff --git a/src/pretix/plugins/ticketoutputpdf/models.py b/src/pretix/plugins/ticketoutputpdf/models.py index 546b8bfa7..4f6eb4d1c 100644 --- a/src/pretix/plugins/ticketoutputpdf/models.py +++ b/src/pretix/plugins/ticketoutputpdf/models.py @@ -27,6 +27,191 @@ from django.utils.translation import gettext_lazy as _ from pretix.base.models import LoggedModel +DEFAULT_TICKET_LAYOUT = '''[{ + "type":"textarea", + "left":"17.50", + "bottom":"274.60", + "fontsize":"16.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"175.00", + "content":"event_name", + "text":"Sample event name", + "align":"left" +}, +{ + "type":"textarea", + "left":"17.50", + "bottom":"262.90", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"110.00", + "content":"itemvar", + "text":"Sample product – sample variation", + "align":"left" +}, +{ + "type":"textarea", + "left":"17.50", + "bottom":"252.50", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"110.00", + "content":"attendee_name", + "text":"John Doe", + "align":"left" +}, +{ + "type":"textarea", + "left":"17.50", + "bottom":"242.10", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"110.00", + "content":"event_begin", + "text":"2016-05-31 20:00", + "align":"left" +}, +{ + "type":"textarea", + "left":"17.50", + "bottom":"231.70", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"110.00", + "content":"seat", + "text":"Ground floor, Row 3, Seat 4", + "align":"left" +}, +{ + "type":"textarea", + "left":"17.50", + "bottom":"204.80", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"110.00", + "content":"event_location", + "text":"Random City", + "align":"left" +}, +{ + "type":"textarea", + "left":"17.50", + "bottom":"194.50", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"30.00", + "content":"order", + "text":"A1B2C", + "align":"left" +}, +{ + "type":"textarea", + "left":"52.50", + "bottom":"194.50", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"45.00", + "content":"price", + "text":"123.45 EUR", + "align":"right" +}, +{ + "type":"textarea", + "left":"102.50", + "bottom":"194.50", + "fontsize":"13.0", + "color":[ + 0, + 0, + 0, + 1 + ], + "fontfamily":"Open Sans", + "bold":false, + "italic":false, + "width":"90.00", + "content":"secret", + "text":"tdmruoekvkpbv1o2mv8xccvqcikvr58u", + "align":"left" +}, +{ + "type":"barcodearea", + "left":"130.40", + "bottom":"204.50", + "size":"64.00" +}, +{ + "type":"poweredby", + "left":"88.72", + "bottom":"10.00", + "size":"20.00", + "content":"dark" +}]''' + def bg_name(instance, filename: str) -> str: secret = get_random_string(length=16, allowed_chars=string.ascii_letters + string.digits) @@ -53,190 +238,7 @@ class TicketLayout(LoggedModel): verbose_name=_('Name') ) layout = models.TextField( - default='''[{ - "type":"textarea", - "left":"17.50", - "bottom":"274.60", - "fontsize":"16.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"175.00", - "content":"event_name", - "text":"Sample event name", - "align":"left" - }, - { - "type":"textarea", - "left":"17.50", - "bottom":"262.90", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"110.00", - "content":"itemvar", - "text":"Sample product – sample variation", - "align":"left" - }, - { - "type":"textarea", - "left":"17.50", - "bottom":"252.50", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"110.00", - "content":"attendee_name", - "text":"John Doe", - "align":"left" - }, - { - "type":"textarea", - "left":"17.50", - "bottom":"242.10", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"110.00", - "content":"event_begin", - "text":"2016-05-31 20:00", - "align":"left" - }, - { - "type":"textarea", - "left":"17.50", - "bottom":"231.70", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"110.00", - "content":"seat", - "text":"Ground floor, Row 3, Seat 4", - "align":"left" - }, - { - "type":"textarea", - "left":"17.50", - "bottom":"204.80", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"110.00", - "content":"event_location", - "text":"Random City", - "align":"left" - }, - { - "type":"textarea", - "left":"17.50", - "bottom":"194.50", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"30.00", - "content":"order", - "text":"A1B2C", - "align":"left" - }, - { - "type":"textarea", - "left":"52.50", - "bottom":"194.50", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"45.00", - "content":"price", - "text":"123.45 EUR", - "align":"right" - }, - { - "type":"textarea", - "left":"102.50", - "bottom":"194.50", - "fontsize":"13.0", - "color":[ - 0, - 0, - 0, - 1 - ], - "fontfamily":"Open Sans", - "bold":false, - "italic":false, - "width":"90.00", - "content":"secret", - "text":"tdmruoekvkpbv1o2mv8xccvqcikvr58u", - "align":"left" - }, - { - "type":"barcodearea", - "left":"130.40", - "bottom":"204.50", - "size":"64.00" - }, - { - "type":"poweredby", - "left":"88.72", - "bottom":"10.00", - "size":"20.00", - "content":"dark" - }]''' + default=DEFAULT_TICKET_LAYOUT ) background = models.FileField(null=True, blank=True, upload_to=bg_name, max_length=255) diff --git a/src/pretix/plugins/ticketoutputpdf/ticketoutput.py b/src/pretix/plugins/ticketoutputpdf/ticketoutput.py index c99504848..a68307cf0 100644 --- a/src/pretix/plugins/ticketoutputpdf/ticketoutput.py +++ b/src/pretix/plugins/ticketoutputpdf/ticketoutput.py @@ -51,7 +51,7 @@ from pretix.base.models import Order, OrderPosition from pretix.base.pdf import Renderer from pretix.base.ticketoutput import BaseTicketOutput from pretix.plugins.ticketoutputpdf.models import ( - TicketLayout, TicketLayoutItem, + TicketLayout, TicketLayoutItem, DEFAULT_TICKET_LAYOUT, ) from pretix.plugins.ticketoutputpdf.signals import override_layout @@ -180,34 +180,7 @@ class PdfTicketOutput(BaseTicketOutput): return self._default_layout() def _default_layout(self): - return [ - {"type": "textarea", "left": "17.50", "bottom": "274.60", "fontsize": "16.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "175.00", "content": "event_name", - "text": "Sample event name", "align": "left"}, - {"type": "textarea", "left": "17.50", "bottom": "262.90", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "110.00", "content": "itemvar", - "text": "Sample product – sample variation", "align": "left"}, - {"type": "textarea", "left": "17.50", "bottom": "252.50", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "110.00", "content": "attendee_name", - "text": "John Doe", "align": "left"}, - {"type": "textarea", "left": "17.50", "bottom": "242.10", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "110.00", - "content": "event_begin", "text": "2017-05-31 20:00", "align": "left"}, - {"type": "textarea", "left": "17.50", "bottom": "204.80", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "110.00", "content": "event_location", - "text": "Random City", "align": "left"}, - {"type": "textarea", "left": "17.50", "bottom": "194.50", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "30.00", "content": "order", - "text": "A1B2C", "align": "left"}, - {"type": "textarea", "left": "52.50", "bottom": "194.50", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "45.00", "content": "price", - "text": "123.45 EUR", "align": "right"}, - {"type": "textarea", "left": "102.50", "bottom": "194.50", "fontsize": "13.0", "color": [0, 0, 0, 1], - "fontfamily": "Open Sans", "bold": False, "italic": False, "width": "90.00", "content": "secret", - "text": "tdmruoekvkpbv1o2mv8xccvqcikvr58u", "align": "left"}, - {"type": "barcodearea", "left": "130.40", "bottom": "204.50", "size": "64.00"}, - {"type": "poweredby", "left": "88.72", "bottom": "10.00", "size": "20.00"}, - ] + return json.loads(DEFAULT_TICKET_LAYOUT) def _migrate_from_old_settings(self): layout = []