From 4baa51e0be674428a2314e08efe43628184bc42a Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Thu, 14 Jan 2010 08:02:49 -0800 Subject: Template panel context cleanup. All panels get a copy of the template context when created and use an updated copy when rendering so they can have full access to context vars and avoid making changes to the shared context. Signed-off-by: Rob Hudson --- debug_toolbar/toolbar/loader.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'debug_toolbar/toolbar/loader.py') diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index c7f999e..8e89aef 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -11,6 +11,9 @@ class DebugToolbar(object): self.config = { 'INTERCEPT_REDIRECTS': True, } + self.template_context = { + 'BASE_URL': self.request.META.get('SCRIPT_NAME', ''), + } # Override this tuple by copying to settings.py as `DEBUG_TOOLBAR_PANELS` self.default_panels = ( 'debug_toolbar.panels.version.VersionDebugPanel', @@ -56,9 +59,8 @@ class DebugToolbar(object): raise exceptions.ImproperlyConfigured, 'Toolbar Panel module "%s" does not define a "%s" class' % (panel_module, panel_classname) try: - panel_instance = panel_class() + panel_instance = panel_class(context=self.template_context) except: - print panel_class raise # Bubble up problem loading panel self.panels.append(panel_instance) @@ -67,7 +69,7 @@ class DebugToolbar(object): """ Renders the overall Toolbar with panels inside. """ - return render_to_string('debug_toolbar/base.html', { - 'panels': self.panels, - 'BASE_URL': self.request.META.get('SCRIPT_NAME', ''), - }) + context = self.template_context.copy() + context.update({ 'panels': self.panels, }) + + return render_to_string('debug_toolbar/base.html', context) -- cgit v1.2.3