aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/template.py
diff options
context:
space:
mode:
Diffstat (limited to 'debug_toolbar/panels/template.py')
-rw-r--r--debug_toolbar/panels/template.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py
index d620a38..79a4871 100644
--- a/debug_toolbar/panels/template.py
+++ b/debug_toolbar/panels/template.py
@@ -4,7 +4,6 @@ from pprint import pformat
from django import http
from django.conf import settings
from django.template.context import get_standard_processors
-from django.template.loader import render_to_string
from django.test.signals import template_rendered
from django.utils.translation import ugettext_lazy as _
from debug_toolbar.panels import DebugPanel
@@ -27,6 +26,7 @@ else:
Template.original_render = Template._render
Template._render = instrumented_test_render
+
# MONSTER monkey-patch
old_template_init = Template.__init__
def new_template_init(self, template_string, origin=None, name='<Unknown Template>'):
@@ -34,21 +34,23 @@ def new_template_init(self, template_string, origin=None, name='<Unknown Templat
self.origin = origin
Template.__init__ = new_template_init
+
class TemplateDebugPanel(DebugPanel):
"""
A panel that lists all templates used during processing of a response.
"""
name = 'Template'
+ template = 'debug_toolbar/panels/templates.html'
has_content = True
-
+
def __init__(self, *args, **kwargs):
- super(self.__class__, self).__init__(*args, **kwargs)
+ super(TemplateDebugPanel, self).__init__(*args, **kwargs)
self.templates = []
template_rendered.connect(self._store_template_info)
-
+
def _store_template_info(self, sender, **kwargs):
context_data = kwargs['context']
-
+
context_list = []
for context_layer in context_data.dicts:
temp_layer = {}
@@ -74,22 +76,22 @@ class TemplateDebugPanel(DebugPanel):
pass
kwargs['context'] = context_list
self.templates.append(kwargs)
-
+
def nav_title(self):
return _('Templates')
-
+
def title(self):
num_templates = len([t for t in self.templates
if not (t['template'].name and t['template'].name.startswith('debug_toolbar/'))])
return _('Templates (%(num_templates)s rendered)') % {'num_templates': num_templates}
-
+
def url(self):
return ''
-
+
def process_request(self, request):
self.request = request
-
- def content(self):
+
+ def process_response(self, request, response):
context_processors = dict(
[
("%s.%s" % (k.__module__, k.__name__),
@@ -116,12 +118,9 @@ class TemplateDebugPanel(DebugPanel):
context_list = template_data.get('context', [])
info['context'] = '\n'.join(context_list)
template_context.append(info)
-
- context = self.context.copy()
- context.update({
+
+ self.record_stats({
'templates': template_context,
'template_dirs': [normpath(x) for x in settings.TEMPLATE_DIRS],
'context_processors': context_processors,
})
-
- return render_to_string('debug_toolbar/panels/templates.html', context)