aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/models.py
diff options
context:
space:
mode:
authorJannis Leidel2012-05-13 12:14:04 +0200
committerJannis Leidel2012-05-13 12:14:04 +0200
commit7f7ea810c1a8ccf2d4211c55d2d635ace66141e7 (patch)
treed4c111645cf463dc369f1fd211ec2339a0e06de5 /debug_toolbar/models.py
parent41e26d8d710d693bffc9d8b85c701c6e891c3573 (diff)
downloaddjango-debug-toolbar-7f7ea810c1a8ccf2d4211c55d2d635ace66141e7.tar.bz2
Fixed the toolbar loading mechanism to only happen when the middleware has been added to the MIDDLEWARE_CLASSES setting.
Diffstat (limited to 'debug_toolbar/models.py')
-rw-r--r--debug_toolbar/models.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/debug_toolbar/models.py b/debug_toolbar/models.py
index 9ea9e86..7ef8601 100644
--- a/debug_toolbar/models.py
+++ b/debug_toolbar/models.py
@@ -1,3 +1,30 @@
+from django.conf import settings
+from django.utils.importlib import import_module
+
from debug_toolbar.toolbar.loader import load_panel_classes
+from debug_toolbar.middleware import DebugToolbarMiddleware
+
+loaded = False
+
+
+def is_toolbar(cls):
+ return (issubclass(cls, DebugToolbarMiddleware) or
+ DebugToolbarMiddleware in getattr(cls, '__bases__', ()))
+
+
+def iter_toolbar_middlewares():
+ global loaded
+ for middleware_path in settings.MIDDLEWARE_CLASSES:
+ try:
+ mod_path, cls_name = middleware_path.rsplit('.', 1)
+ mod = import_module(mod_path)
+ middleware_cls = getattr(mod, cls_name)
+ except (AttributeError, ImportError, ValueError):
+ continue
+ if is_toolbar(middleware_cls) and not loaded:
+ # we have a hit!
+ loaded = True
+ yield middleware_cls
-load_panel_classes()
+for middleware_cls in iter_toolbar_middlewares():
+ load_panel_classes()