aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-12-15 13:06:16 +0100
committerAymeric Augustin2013-12-15 13:06:16 +0100
commit5360a2ba9c5b866ce2502aa43606b2647acea63b (patch)
treea329bde5cc206f57ac142cef8adba456b5e4b709
parentdbed3e7c72f930c285f17206879f6bd1d46f67a1 (diff)
downloaddjango-debug-toolbar-5360a2ba9c5b866ce2502aa43606b2647acea63b.tar.bz2
Properly disable instrumentation for the template panel.
It's important to disconnect the signal at the end of a request because the toolbar now stores panels for past request. Fix #491 (presumably).
-rw-r--r--debug_toolbar/panels/templates/panel.py10
-rw-r--r--tests/panels/test_template.py2
2 files changed, 8 insertions, 4 deletions
diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py
index df39804..74f28b0 100644
--- a/debug_toolbar/panels/templates/panel.py
+++ b/debug_toolbar/panels/templates/panel.py
@@ -81,12 +81,8 @@ class TemplatesPanel(Panel):
def __init__(self, *args, **kwargs):
super(TemplatesPanel, self).__init__(*args, **kwargs)
self.templates = []
- template_rendered.connect(self._store_template_info)
def _store_template_info(self, sender, **kwargs):
- if not self.enabled:
- return
-
template, context = kwargs['template'], kwargs['context']
# Skip templates that we are generating through the debug toolbar.
@@ -157,6 +153,12 @@ class TemplatesPanel(Panel):
url(r'^template_source/$', 'template_source', name='template_source'),
)
+ def enable_instrumentation(self):
+ template_rendered.connect(self._store_template_info)
+
+ def disable_instrumentation(self):
+ template_rendered.disconnect(self._store_template_info)
+
def process_response(self, request, response):
template_context = []
for template_data in self.templates:
diff --git a/tests/panels/test_template.py b/tests/panels/test_template.py
index 72e90c0..8a36f06 100644
--- a/tests/panels/test_template.py
+++ b/tests/panels/test_template.py
@@ -15,11 +15,13 @@ class TemplatesPanelTestCase(BaseTestCase):
def setUp(self):
super(TemplatesPanelTestCase, self).setUp()
self.panel = self.toolbar.get_panel_by_id('TemplatesPanel')
+ self.panel.enable_instrumentation()
self.sql_panel = self.toolbar.get_panel_by_id('SQLPanel')
self.sql_panel.enable_instrumentation()
def tearDown(self):
self.sql_panel.disable_instrumentation()
+ self.panel.disable_instrumentation()
super(TemplatesPanelTestCase, self).tearDown()
def test_queryset_hook(self):