From b29df2ae00b4dbf671f31d22fdbb202332770238 Mon Sep 17 00:00:00 2001 From: lcduong Date: Wed, 9 Oct 2024 16:17:02 +0700 Subject: [PATCH 1/3] upgrade django version from 4.2 to 5.1 --- pyproject.toml | 6 +- src/pretix/base/js_catalog_template.py | 104 +++++++++++++++++++++++++ src/pretix/base/signals.py | 26 +++---- src/pretix/presale/views/widget.py | 3 +- 4 files changed, 119 insertions(+), 20 deletions(-) create mode 100644 src/pretix/base/js_catalog_template.py diff --git a/pyproject.toml b/pyproject.toml index f3f6535ae..9e7962923 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,10 +16,10 @@ classifiers = [ "Environment :: Web Environment", "License :: OSI Approved :: Apache License, Version 2.0", "Programming Language :: Python :: 3.11", - "Framework :: Django :: 4.2", + "Framework :: Django :: 5.1", ] dependencies = [ - 'Django==4.2.*', + 'Django==5.1.*', 'djangorestframework==3.15.*', 'python-dateutil==2.9.*', 'isoweek', @@ -103,7 +103,7 @@ dependencies = [ [project.optional-dependencies] memcached = ["pylibmc"] dev = [ - 'django-debug-toolbar==4.0.*', + 'django-debug-toolbar==4.4.*', 'pycodestyle==2.12.*', 'pyflakes==3.2.*', 'flake8==7.1.*', diff --git a/src/pretix/base/js_catalog_template.py b/src/pretix/base/js_catalog_template.py new file mode 100644 index 000000000..63c123df8 --- /dev/null +++ b/src/pretix/base/js_catalog_template.py @@ -0,0 +1,104 @@ +js_catalog_template = r""" +{% autoescape off %} +'use strict'; +{ + const globals = this; + const django = globals.django || (globals.django = {}); + + {% if plural %} + django.pluralidx = function(n) { + const v = {{ plural }}; + if (typeof v === 'boolean') { + return v ? 1 : 0; + } else { + return v; + } + }; + {% else %} + django.pluralidx = function(count) { return (count == 1) ? 0 : 1; }; + {% endif %} + + /* gettext library */ + + django.catalog = django.catalog || {}; + {% if catalog_str %} + const newcatalog = {{ catalog_str }}; + for (const key in newcatalog) { + django.catalog[key] = newcatalog[key]; + } + {% endif %} + + if (!django.jsi18n_initialized) { + django.gettext = function(msgid) { + const value = django.catalog[msgid]; + if (typeof value === 'undefined') { + return msgid; + } else { + return (typeof value === 'string') ? value : value[0]; + } + }; + + django.ngettext = function(singular, plural, count) { + const value = django.catalog[singular]; + if (typeof value === 'undefined') { + return (count == 1) ? singular : plural; + } else { + return value.constructor === Array ? value[django.pluralidx(count)] : value; + } + }; + + django.gettext_noop = function(msgid) { return msgid; }; + + django.pgettext = function(context, msgid) { + let value = django.gettext(context + '\x04' + msgid); + if (value.includes('\x04')) { + value = msgid; + } + return value; + }; + + django.npgettext = function(context, singular, plural, count) { + let value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count); + if (value.includes('\x04')) { + value = django.ngettext(singular, plural, count); + } + return value; + }; + + django.interpolate = function(fmt, obj, named) { + if (named) { + return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); + } else { + return fmt.replace(/%s/g, function(match){return String(obj.shift())}); + } + }; + + + /* formatting library */ + + django.formats = {{ formats_str }}; + + django.get_format = function(format_type) { + const value = django.formats[format_type]; + if (typeof value === 'undefined') { + return format_type; + } else { + return value; + } + }; + + /* add to global namespace */ + globals.pluralidx = django.pluralidx; + globals.gettext = django.gettext; + globals.ngettext = django.ngettext; + globals.gettext_noop = django.gettext_noop; + globals.pgettext = django.pgettext; + globals.npgettext = django.npgettext; + globals.interpolate = django.interpolate; + globals.get_format = django.get_format; + + django.jsi18n_initialized = true; + } +}; +{% endautoescape %} +""" # NOQA diff --git a/src/pretix/base/signals.py b/src/pretix/base/signals.py index 2d4f5bcc4..eb0c089d0 100644 --- a/src/pretix/base/signals.py +++ b/src/pretix/base/signals.py @@ -21,10 +21,16 @@ def _populate_app_cache(): class EventPluginSignal(django.dispatch.Signal): """ This is an extension to Django's built-in signals which differs in a way that it sends - out it's events only to receivers which belong to plugins that are enabled for the given + out its events only to receivers which belong to plugins that are enabled for the given Event. """ + def get_live_receivers(self, sender): + receivers = self._live_receivers(sender) + if not receivers: + return [] + return receivers[0] + def _is_active(self, sender, receiver): if sender is None: # Send to all events! @@ -65,7 +71,7 @@ def send(self, sender: Event, **named) -> List[Tuple[Callable, Any]]: if not app_cache: _populate_app_cache() - for receiver in self._sorted_receivers(sender): + for receiver in self.get_live_receivers(sender): if self._is_active(sender, receiver): response = receiver(signal=self, sender=sender, **named) responses.append((receiver, response)) @@ -89,7 +95,7 @@ def send_chained(self, sender: Event, chain_kwarg_name, **named) -> List[Tuple[C if not app_cache: _populate_app_cache() - for receiver in self._sorted_receivers(sender): + for receiver in self.get_live_receivers(sender): if self._is_active(sender, receiver): named[chain_kwarg_name] = response response = receiver(signal=self, sender=sender, **named) @@ -116,7 +122,7 @@ def send_robust(self, sender: Event, **named) -> List[Tuple[Callable, Any]]: if not app_cache: _populate_app_cache() - for receiver in self._sorted_receivers(sender): + for receiver in self.get_live_receivers(sender): if self._is_active(sender, receiver): try: response = receiver(signal=self, sender=sender, **named) @@ -126,18 +132,6 @@ def send_robust(self, sender: Event, **named) -> List[Tuple[Callable, Any]]: responses.append((receiver, response)) return responses - def _sorted_receivers(self, sender): - orig_list = self._live_receivers(sender) - sorted_list = sorted( - orig_list, - key=lambda receiver: ( - 0 if any(receiver.__module__.startswith(m) for m in settings.CORE_MODULES) else 1, - receiver.__module__, - receiver.__name__, - ) - ) - return sorted_list - class GlobalSignal(django.dispatch.Signal): def send_chained(self, sender: Event, chain_kwarg_name, **named) -> List[Tuple[Callable, Any]]: diff --git a/src/pretix/presale/views/widget.py b/src/pretix/presale/views/widget.py index 692038ece..312d08a57 100644 --- a/src/pretix/presale/views/widget.py +++ b/src/pretix/presale/views/widget.py @@ -26,11 +26,12 @@ from django.views.decorators.gzip import gzip_page from django.views.decorators.http import condition from django.views.i18n import ( - JavaScriptCatalog, get_formats, js_catalog_template, + JavaScriptCatalog, get_formats, ) from lxml import html from pretix.base.i18n import language +from pretix.base.js_catalog_template import js_catalog_template from pretix.base.models import CartPosition, Event, Quota, SubEvent, Voucher from pretix.base.services.cart import error_messages from pretix.base.settings import GlobalSettingsObject From cbfaf18e29d2afe18f448bc5ff5c296aa3aeecb8 Mon Sep 17 00:00:00 2001 From: lcduong Date: Thu, 24 Oct 2024 17:25:54 +0700 Subject: [PATCH 2/3] Fix Dockerfile and isort in pipeline --- src/pretix/presale/views/widget.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pretix/presale/views/widget.py b/src/pretix/presale/views/widget.py index 312d08a57..f28bcdad1 100644 --- a/src/pretix/presale/views/widget.py +++ b/src/pretix/presale/views/widget.py @@ -25,9 +25,7 @@ from django.views.decorators.cache import cache_page from django.views.decorators.gzip import gzip_page from django.views.decorators.http import condition -from django.views.i18n import ( - JavaScriptCatalog, get_formats, -) +from django.views.i18n import JavaScriptCatalog, get_formats from lxml import html from pretix.base.i18n import language From d3b491e915ecd787dd994d9aaf158b6263e1bd60 Mon Sep 17 00:00:00 2001 From: lcduong Date: Thu, 24 Oct 2024 17:35:11 +0700 Subject: [PATCH 3/3] Fix Dockerfile in pipeline --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5081fff62..17765dd2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -68,8 +68,7 @@ RUN chmod +x /usr/local/bin/pretix && \ cd /pretix/src && \ rm -f pretix.cfg && \ mkdir -p data && \ - chown -R pretixuser:pretixuser /pretix /data data && \ - sudo -u pretixuser make production + chown -R pretixuser:pretixuser /pretix /data data USER pretixuser VOLUME ["/etc/pretix", "/data"]