Fix EventPluginSignal to recognize Django apps with custom app labels

This commit is contained in:
Raphael Michel
2017-07-12 19:14:28 +02:00
parent c1158c3175
commit ae910eb731

View File

@@ -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)