Skip to content

Commit ad110e0

Browse files
committed
Dont access __copy__ when it doesnt work. Preprocess context list so the dictionary cannot be modified.
1 parent a03b6a0 commit ad110e0

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

debug_toolbar/panels/template.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,29 @@ def __init__(self, *args, **kwargs):
4747
template_rendered.connect(self._store_template_info)
4848

4949
def _store_template_info(self, sender, **kwargs):
50-
kwargs['context'] = kwargs['context'].__copy__()
50+
context_data = kwargs['context']
51+
52+
context_list = []
53+
for context_layer in context_data.dicts:
54+
if hasattr(context_layer, 'items'):
55+
for key, value in context_layer.items():
56+
# Replace any request elements - they have a large
57+
# unicode representation and the request data is
58+
# already made available from the Request Vars panel.
59+
if isinstance(value, http.HttpRequest):
60+
context_layer[key] = '<<request>>'
61+
# Replace the debugging sql_queries element. The SQL
62+
# data is already made available from the SQL panel.
63+
elif key == 'sql_queries' and isinstance(value, list):
64+
context_layer[key] = '<<sql_queries>>'
65+
# Replace LANGUAGES, which is available in i18n context processor
66+
elif key == 'LANGUAGES' and isinstance(value, tuple):
67+
context_layer[key] = '<<languages>>'
68+
try:
69+
context_list.append(pformat(context_layer))
70+
except UnicodeEncodeError:
71+
pass
72+
kwargs['context'] = context_list
5173
self.templates.append(kwargs)
5274

5375
def nav_title(self):
@@ -88,28 +110,7 @@ def content(self):
88110
info['template'] = template
89111
# Clean up context for better readability
90112
if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('SHOW_TEMPLATE_CONTEXT', True):
91-
context_data = template_data.get('context', None)
92-
93-
context_list = []
94-
for context_layer in context_data.dicts:
95-
if hasattr(context_layer, 'items'):
96-
for key, value in context_layer.items():
97-
# Replace any request elements - they have a large
98-
# unicode representation and the request data is
99-
# already made available from the Request Vars panel.
100-
if isinstance(value, http.HttpRequest):
101-
context_layer[key] = '<<request>>'
102-
# Replace the debugging sql_queries element. The SQL
103-
# data is already made available from the SQL panel.
104-
elif key == 'sql_queries' and isinstance(value, list):
105-
context_layer[key] = '<<sql_queries>>'
106-
# Replace LANGUAGES, which is available in i18n context processor
107-
elif key == 'LANGUAGES' and isinstance(value, tuple):
108-
context_layer[key] = '<<languages>>'
109-
try:
110-
context_list.append(pformat(context_layer))
111-
except UnicodeEncodeError:
112-
pass
113+
context_list = template_data.get('context', [])
113114
info['context'] = '\n'.join(context_list)
114115
template_context.append(info)
115116

example/example.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)