diff options
| author | Aymeric Augustin | 2013-11-10 09:58:56 -0800 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-10 09:58:56 -0800 |
| commit | d889bf25d98e6d3c8dde01b207f9ba5f3d91a806 (patch) | |
| tree | 97967ae5b01c7531954b983606bc78498a128d8a /debug_toolbar/panels/template.py | |
| parent | 8c7a8ec6529063853c9ff36da72a38841ca5e235 (diff) | |
| parent | f5eaa8ebb0d1ca13aa2453ef88bb1eb223757716 (diff) | |
| download | django-debug-toolbar-d889bf25d98e6d3c8dde01b207f9ba5f3d91a806.tar.bz2 | |
Merge pull request #453 from aaugustin/disable-instrumentation-for-disabled-panels
Disable instrumentation for disabled panels
Diffstat (limited to 'debug_toolbar/panels/template.py')
| -rw-r--r-- | debug_toolbar/panels/template.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index 5bc0d2b..6523155 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -18,9 +18,9 @@ from debug_toolbar.utils.settings import CONFIG # Code taken and adapted from Simon Willison and Django Snippets: # http://www.djangosnippets.org/snippets/766/ -# Monkeypatch instrumented test renderer from django.test.utils - we could use -# django.test.utils.setup_test_environment for this but that would also set up -# e-mail interception, which we don't want +# Monkey-patch to enable the template_rendered signal. The receiver returns +# immediately when the panel is disabled to keep the overhead small. + from django.test.utils import instrumented_test_render from django.template import Template @@ -56,13 +56,17 @@ class TemplateDebugPanel(DebugPanel): template_rendered.connect(self._store_template_info) def _store_template_info(self, sender, **kwargs): - t = kwargs['template'] - if t.name and t.name.startswith('debug_toolbar/'): - return # skip templates that we are generating through the debug toolbar. - context_data = kwargs['context'] + if not self.enabled: + return + + template, context = kwargs['template'], kwargs['context'] + + # Skip templates that we are generating through the debug toolbar. + if template.name and template.name.startswith('debug_toolbar/'): + return context_list = [] - for context_layer in context_data.dicts: + for context_layer in context.dicts: temp_layer = {} if hasattr(context_layer, 'items'): for key, value in context_layer.items(): @@ -102,6 +106,7 @@ class TemplateDebugPanel(DebugPanel): context_list.append(pformat(temp_layer)) except UnicodeEncodeError: pass + kwargs['context'] = [force_text(item) for item in context_list] self.templates.append(kwargs) |
