Skip to content

Load the content of panels dynamically #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 10, 2013
Next Next commit
Avoid some implicit global lookups.
They made it impossible to preserve panel data after the end of a
request.
  • Loading branch information
aaugustin committed Nov 10, 2013
commit 631bbd18c10f572e31ef30f4dc78df942beeffd4
11 changes: 5 additions & 6 deletions debug_toolbar/panels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -44,16 +45,14 @@ def content(self):
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

Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/toolbar/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_panels(self):
"""
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

Expand Down