Skip to content

Commit 5b45537

Browse files
committed
Updated the template panel, and corrected an issue in the headers panel
1 parent 2519b2c commit 5b45537

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

debug_toolbar/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def process_response(self, request, response):
123123
)
124124
response.cookies = cookies
125125
if 'gzip' not in response.get('Content-Encoding', '') and \
126-
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES:
126+
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES:
127127
toolbar.stats = {}
128128
for panel in toolbar.panels:
129129
panel.process_response(request, response)

debug_toolbar/panels/headers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ def process_request(self, request):
4747
self.headers = dict(
4848
[(k, request.META[k]) for k in self.header_filter if k in request.META]
4949
)
50+
51+
def process_response(self, request, response):
5052
self.stats = {
5153
'headers': self.headers
5254
}
5355
toolbar = DebugToolbarMiddleware.get_current()
5456
toolbar.stats['headers'] = self.stats
5557

56-
57-
def process_response(self, request, response):
58-
request.debug_toolbar.stats['headers'] = self.headers
59-
6058
def content(self):
6159
context = self.context.copy()
6260
context.update(self.stats)

debug_toolbar/panels/template.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.template.loader import render_to_string
88
from django.test.signals import template_rendered
99
from django.utils.translation import ugettext_lazy as _
10+
from debug_toolbar.middleware import DebugToolbarMiddleware
1011
from debug_toolbar.panels import DebugPanel
1112

1213
# Code taken and adapted from Simon Willison and Django Snippets:
@@ -40,15 +41,15 @@ class TemplateDebugPanel(DebugPanel):
4041
"""
4142
name = 'Template'
4243
has_content = True
43-
44+
4445
def __init__(self, *args, **kwargs):
4546
super(self.__class__, self).__init__(*args, **kwargs)
4647
self.templates = []
4748
template_rendered.connect(self._store_template_info)
48-
49+
4950
def _store_template_info(self, sender, **kwargs):
5051
context_data = kwargs['context']
51-
52+
5253
context_list = []
5354
for context_layer in context_data.dicts:
5455
temp_layer = {}
@@ -74,22 +75,22 @@ def _store_template_info(self, sender, **kwargs):
7475
pass
7576
kwargs['context'] = context_list
7677
self.templates.append(kwargs)
77-
78+
7879
def nav_title(self):
7980
return _('Templates')
80-
81+
8182
def title(self):
8283
num_templates = len([t for t in self.templates
8384
if not (t['template'].name and t['template'].name.startswith('debug_toolbar/'))])
8485
return _('Templates (%(num_templates)s rendered)') % {'num_templates': num_templates}
85-
86+
8687
def url(self):
8788
return ''
88-
89+
8990
def process_request(self, request):
9091
self.request = request
91-
92-
def content(self):
92+
93+
def process_response(self, request, response):
9394
context_processors = dict(
9495
[
9596
("%s.%s" % (k.__module__, k.__name__),
@@ -116,12 +117,17 @@ def content(self):
116117
context_list = template_data.get('context', [])
117118
info['context'] = '\n'.join(context_list)
118119
template_context.append(info)
119-
120-
context = self.context.copy()
121-
context.update({
120+
121+
self.stats = {
122122
'templates': template_context,
123123
'template_dirs': [normpath(x) for x in settings.TEMPLATE_DIRS],
124124
'context_processors': context_processors,
125-
})
126-
125+
}
126+
127+
toolbar = DebugToolbarMiddleware.get_current()
128+
toolbar.stats['template'] = self.stats
129+
130+
def content(self):
131+
context = self.context.copy()
132+
context.update(self.stats)
127133
return render_to_string('debug_toolbar/panels/templates.html', context)

0 commit comments

Comments
 (0)