Skip to content

Commit 631bbd1

Browse files
committed
Avoid some implicit global lookups.
They made it impossible to preserve panel data after the end of a request.
1 parent 0b4fc3e commit 631bbd1

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

debug_toolbar/panels/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class DebugPanel(object):
1818
context = {}
1919

2020
# Panel methods
21-
def __init__(self, context={}):
21+
def __init__(self, toolbar, context={}):
22+
self.toolbar = toolbar
2223
self.context.update(context)
2324
self.slug = slugify(self.name)
2425

@@ -44,16 +45,14 @@ def content(self):
4445
return render_to_string(self.template, context)
4546

4647
def record_stats(self, stats):
47-
toolbar = DebugToolbarMiddleware.get_current()
48-
panel_stats = toolbar.stats.get(self.slug)
48+
panel_stats = self.toolbar.stats.get(self.slug)
4949
if panel_stats:
5050
panel_stats.update(stats)
5151
else:
52-
toolbar.stats[self.slug] = stats
52+
self.toolbar.stats[self.slug] = stats
5353

5454
def get_stats(self):
55-
toolbar = DebugToolbarMiddleware.get_current()
56-
return toolbar.stats.get(self.slug, {})
55+
return self.toolbar.stats.get(self.slug, {})
5756

5857
# Standard middleware methods
5958

debug_toolbar/toolbar/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def load_panels(self):
4545
"""
4646
global panel_classes
4747
for panel_class in panel_classes:
48-
panel_instance = panel_class(context=self.template_context)
48+
panel_instance = panel_class(self, context=self.template_context)
4949

5050
self._panels[panel_class] = panel_instance
5151

0 commit comments

Comments
 (0)