From ae910eb7319f4acb6fa93e14296cd665df2fe55a Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 12 Jul 2017 19:14:28 +0200 Subject: [PATCH] Fix EventPluginSignal to recognize Django apps with custom app labels --- src/pretix/base/signals.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pretix/base/signals.py b/src/pretix/base/signals.py index b30271372..6486087f7 100644 --- a/src/pretix/base/signals.py +++ b/src/pretix/base/signals.py @@ -8,6 +8,15 @@ from django.dispatch.dispatcher import NO_RECEIVERS from .models import Event +app_cache = {} + + +def _populate_app_cache(): + global app_cache + apps.check_apps_ready() + for ac in apps.app_configs.values(): + app_cache[ac.name] = ac + class EventPluginSignal(django.dispatch.Signal): """ @@ -30,18 +39,16 @@ class EventPluginSignal(django.dispatch.Signal): if not self.receivers or self.sender_receivers_cache.get(sender) is NO_RECEIVERS: return responses + if not app_cache: + _populate_app_cache() + for receiver in self._live_receivers(sender): # Find the Django application this belongs to searchpath = receiver.__module__ - app = None mod = None while True: - try: - if apps.is_installed(searchpath): - app = apps.get_app_config(searchpath.split(".")[-1]) - except LookupError: - pass - if "." not in searchpath: + app = app_cache.get(searchpath) + if "." not in searchpath or app: break searchpath, mod = searchpath.rsplit(".", 1)