Skip to content

Commit b838722

Browse files
committed
Simplify code introduced in 7f7ea81.
1 parent 363c4a8 commit b838722

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

debug_toolbar/models.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,16 @@
66
from debug_toolbar.toolbar.loader import load_panel_classes
77
from debug_toolbar.middleware import DebugToolbarMiddleware
88

9-
loaded = False
109

11-
12-
def is_toolbar(cls):
13-
return (issubclass(cls, DebugToolbarMiddleware) or
14-
DebugToolbarMiddleware in getattr(cls, '__bases__', ()))
15-
16-
17-
def iter_toolbar_middlewares():
18-
global loaded
19-
for middleware_path in settings.MIDDLEWARE_CLASSES:
20-
try:
21-
mod_path, cls_name = middleware_path.rsplit('.', 1)
22-
mod = import_module(mod_path)
23-
middleware_cls = getattr(mod, cls_name)
24-
except (AttributeError, ImportError, ValueError):
25-
continue
26-
if is_toolbar(middleware_cls) and not loaded:
27-
# we have a hit!
28-
loaded = True
29-
yield middleware_cls
30-
31-
for middleware_cls in iter_toolbar_middlewares():
32-
load_panel_classes()
10+
for middleware_path in settings.MIDDLEWARE_CLASSES:
11+
# Replace this with import_by_path in Django >= 1.6.
12+
try:
13+
mod_path, cls_name = middleware_path.rsplit('.', 1)
14+
mod = import_module(mod_path)
15+
middleware_cls = getattr(mod, cls_name)
16+
except (AttributeError, ImportError, ValueError):
17+
continue
18+
19+
if issubclass(middleware_cls, DebugToolbarMiddleware):
20+
load_panel_classes()
21+
break

0 commit comments

Comments
 (0)