From c33ce081f270b43fffe8af33bf50ae821aa12fcf Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 29 Nov 2013 22:22:38 +0100 Subject: Stop sharing unsafely a context dict across threads. Panels that need to share data with other panels shall do it through the record_stats / get_stats API. Statistics are automatically pushed to the template context. Fix #450. --- debug_toolbar/panels/__init__.py | 16 ++++------------ debug_toolbar/panels/timer.py | 4 +--- debug_toolbar/toolbar.py | 6 ++---- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py index 1b2a767..178ea6f 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -9,16 +9,10 @@ class Panel(object): """ Base class for panels. """ - - # We'll maintain a local context instance so we can expose our template - # context variables to panels which need them. (But see issue #450.) - context = {} - - # Private panel methods - - def __init__(self, toolbar, context={}): + def __init__(self, toolbar): self.toolbar = toolbar - self.context.update(context) + + # Private panel properties @property def panel_id(self): @@ -81,9 +75,7 @@ class Panel(object): template's context. """ if self.has_content: - context = self.context.copy() - context.update(self.get_stats()) - return render_to_string(self.template, context) + return render_to_string(self.template, self.get_stats()) # URLs for panel-specific views diff --git a/debug_toolbar/panels/timer.py b/debug_toolbar/panels/timer.py index 6df4d4d..6b36bf9 100644 --- a/debug_toolbar/panels/timer.py +++ b/debug_toolbar/panels/timer.py @@ -45,9 +45,7 @@ class TimerPanel(Panel): (_('Elapsed time'), _('%(total_time)0.3f msec') % stats), (_('Context switches'), _('%(vcsw)d voluntary, %(ivcsw)d involuntary') % stats), ) - context = self.context.copy() - context.update({'rows': rows}) - return render_to_string(self.template, context) + return render_to_string(self.template, {'rows': rows}) def process_request(self, request): self._start_time = time.time() diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index d50ad52..80b6dff 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -20,10 +20,9 @@ class DebugToolbar(object): def __init__(self, request): self.request = request self.config = dt_settings.CONFIG.copy() - self.template_context = {'toolbar': self} self._panels = SortedDict() for panel_class in self.get_panel_classes(): - panel_instance = panel_class(self, context=self.template_context) + panel_instance = panel_class(self) self._panels[panel_instance.panel_id] = panel_instance self.stats = {} self.store_id = None @@ -58,8 +57,7 @@ class DebugToolbar(object): """ if not self.should_render_panels(): self.store() - context = self.template_context.copy() - return render_to_string('debug_toolbar/base.html', context) + return render_to_string('debug_toolbar/base.html', {'toolbar': self}) # Handle storing toolbars in memory and fetching them later on -- cgit v1.2.3