mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Consistently set default background PDFs on server, not client (#2840)
Co-authored-by: Martin Gross <gross@rami.io>
This commit is contained in:
47
src/pretix/multidomain/utils.py
Normal file
47
src/pretix/multidomain/utils.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#
|
||||
# This file is part of pretix (Community Edition).
|
||||
#
|
||||
# Copyright (C) 2014-2020 Raphael Michel and contributors
|
||||
# Copyright (C) 2020-2021 rami.io GmbH and contributors
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
|
||||
# Public License as published by the Free Software Foundation in version 3 of the License.
|
||||
#
|
||||
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
|
||||
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
|
||||
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
|
||||
# this file, see <https://pretix.eu/about/en/license>.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
from urllib.parse import urljoin, urlsplit
|
||||
|
||||
from django.conf import settings
|
||||
from django.templatetags.static import static
|
||||
|
||||
from pretix.base.models import Event
|
||||
from pretix.multidomain.urlreverse import (
|
||||
get_event_domain, get_organizer_domain,
|
||||
)
|
||||
|
||||
|
||||
def static_absolute(object, path):
|
||||
sp = static(path)
|
||||
if sp.startswith("/"):
|
||||
if isinstance(object, Event):
|
||||
domain = get_event_domain(object, fallback=True)
|
||||
else:
|
||||
domain = get_organizer_domain(object)
|
||||
if domain:
|
||||
siteurlsplit = urlsplit(settings.SITE_URL)
|
||||
if siteurlsplit.port and siteurlsplit.port not in (80, 443):
|
||||
domain = '%s:%d' % (domain, siteurlsplit.port)
|
||||
sp = urljoin('%s://%s' % (siteurlsplit.scheme, domain), sp)
|
||||
else:
|
||||
sp = urljoin(settings.SITE_URL, sp)
|
||||
return sp
|
||||
@@ -24,6 +24,7 @@ from rest_framework import viewsets
|
||||
from pretix.api.serializers.i18n import I18nAwareModelSerializer
|
||||
from pretix.api.serializers.order import CompatibleJSONField
|
||||
|
||||
from ...multidomain.utils import static_absolute
|
||||
from .models import BadgeItem, BadgeLayout
|
||||
|
||||
|
||||
@@ -47,6 +48,12 @@ class BadgeLayoutSerializer(I18nAwareModelSerializer):
|
||||
model = BadgeLayout
|
||||
fields = ('id', 'name', 'default', 'layout', 'background', 'item_assignments')
|
||||
|
||||
def to_representation(self, instance):
|
||||
d = super().to_representation(instance)
|
||||
if not d['background']:
|
||||
d['background'] = static_absolute(instance.event, "pretixplugins/badges/badge_default_a6l.pdf")
|
||||
return d
|
||||
|
||||
|
||||
class BadgeLayoutViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
serializer_class = BadgeLayoutSerializer
|
||||
|
||||
@@ -24,6 +24,7 @@ from rest_framework import viewsets
|
||||
from pretix.api.serializers.i18n import I18nAwareModelSerializer
|
||||
from pretix.api.serializers.order import CompatibleJSONField
|
||||
|
||||
from ...multidomain.utils import static_absolute
|
||||
from .models import TicketLayout, TicketLayoutItem
|
||||
|
||||
|
||||
@@ -49,6 +50,12 @@ class TicketLayoutSerializer(I18nAwareModelSerializer):
|
||||
model = TicketLayout
|
||||
fields = ('id', 'name', 'default', 'layout', 'background', 'item_assignments')
|
||||
|
||||
def to_representation(self, instance):
|
||||
d = super().to_representation(instance)
|
||||
if not d['background']:
|
||||
d['background'] = static_absolute(instance.event, "pretixpresale/pdf/ticket_default_a4.pdf")
|
||||
return d
|
||||
|
||||
|
||||
class TicketLayoutViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
serializer_class = TicketLayoutSerializer
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext, gettext_lazy as _
|
||||
|
||||
from pretix import __version__ as version
|
||||
|
||||
@@ -63,3 +63,11 @@ class TicketOutputPdfApp(AppConfig):
|
||||
except ImportError:
|
||||
errs.append("Python package 'reportlab' is not installed.")
|
||||
return errs
|
||||
|
||||
def installed(self, event):
|
||||
event.ticket_layouts.get_or_create(
|
||||
default=True,
|
||||
defaults={
|
||||
'name': gettext('Default layout'),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ RES_LAYOUT = {
|
||||
'default': True,
|
||||
'item_assignments': [{'item': 1}],
|
||||
'layout': [{'a': 2}],
|
||||
'background': None
|
||||
'background': 'http://example.com/static/pretixplugins/badges/badge_default_a6l.pdf'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ RES_LAYOUT = {
|
||||
'default': True,
|
||||
'item_assignments': [{'item': 1, 'sales_channel': 'web'}],
|
||||
'layout': [{'a': 2}],
|
||||
'background': None
|
||||
'background': 'http://example.com/static/pretixpresale/pdf/ticket_default_a4.pdf'
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user