aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-09 19:05:27 +0100
committerAymeric Augustin2013-11-10 10:39:42 +0100
commit631bbd18c10f572e31ef30f4dc78df942beeffd4 (patch)
tree39ba5916e0dcb66da58f6d1d86e25ed4b70c9e1c
parent0b4fc3e4c30a645e4d7a706d890c74a82c88cb8c (diff)
downloaddjango-debug-toolbar-631bbd18c10f572e31ef30f4dc78df942beeffd4.tar.bz2
Avoid some implicit global lookups.
They made it impossible to preserve panel data after the end of a request.
-rw-r--r--debug_toolbar/panels/__init__.py11
-rw-r--r--debug_toolbar/toolbar/loader.py2
2 files changed, 6 insertions, 7 deletions
diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py
index 8be87e1..a48b1b3 100644
--- a/debug_toolbar/panels/__init__.py
+++ b/debug_toolbar/panels/__init__.py
@@ -18,7 +18,8 @@ class DebugPanel(object):
context = {}
# Panel methods
- def __init__(self, context={}):
+ def __init__(self, toolbar, context={}):
+ self.toolbar = toolbar
self.context.update(context)
self.slug = slugify(self.name)
@@ -44,16 +45,14 @@ class DebugPanel(object):
return render_to_string(self.template, context)
def record_stats(self, stats):
- toolbar = DebugToolbarMiddleware.get_current()
- panel_stats = toolbar.stats.get(self.slug)
+ panel_stats = self.toolbar.stats.get(self.slug)
if panel_stats:
panel_stats.update(stats)
else:
- toolbar.stats[self.slug] = stats
+ self.toolbar.stats[self.slug] = stats
def get_stats(self):
- toolbar = DebugToolbarMiddleware.get_current()
- return toolbar.stats.get(self.slug, {})
+ return self.toolbar.stats.get(self.slug, {})
# Standard middleware methods
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py
index c8630a9..7b525b6 100644
--- a/debug_toolbar/toolbar/loader.py
+++ b/debug_toolbar/toolbar/loader.py
@@ -45,7 +45,7 @@ class DebugToolbar(object):
"""
global panel_classes
for panel_class in panel_classes:
- panel_instance = panel_class(context=self.template_context)
+ panel_instance = panel_class(self, context=self.template_context)
self._panels[panel_class] = panel_instance