From ad110e020cbae062ba024d91223df519af3adc96 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 12 Jul 2011 13:08:40 -0700 Subject: Dont access __copy__ when it doesnt work. Preprocess context list so the dictionary cannot be modified. --- debug_toolbar/panels/template.py | 47 ++++++++++++++++++++------------------- example/example.db | Bin 55296 -> 55296 bytes 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index e6c6216..0715c0a 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -47,7 +47,29 @@ class TemplateDebugPanel(DebugPanel): template_rendered.connect(self._store_template_info) def _store_template_info(self, sender, **kwargs): - kwargs['context'] = kwargs['context'].__copy__() + context_data = kwargs['context'] + + context_list = [] + for context_layer in context_data.dicts: + if hasattr(context_layer, 'items'): + for key, value in context_layer.items(): + # Replace any request elements - they have a large + # unicode representation and the request data is + # already made available from the Request Vars panel. + if isinstance(value, http.HttpRequest): + context_layer[key] = '<>' + # Replace the debugging sql_queries element. The SQL + # data is already made available from the SQL panel. + elif key == 'sql_queries' and isinstance(value, list): + context_layer[key] = '<>' + # Replace LANGUAGES, which is available in i18n context processor + elif key == 'LANGUAGES' and isinstance(value, tuple): + context_layer[key] = '<>' + try: + context_list.append(pformat(context_layer)) + except UnicodeEncodeError: + pass + kwargs['context'] = context_list self.templates.append(kwargs) def nav_title(self): @@ -88,28 +110,7 @@ class TemplateDebugPanel(DebugPanel): info['template'] = template # Clean up context for better readability if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('SHOW_TEMPLATE_CONTEXT', True): - context_data = template_data.get('context', None) - - context_list = [] - for context_layer in context_data.dicts: - if hasattr(context_layer, 'items'): - for key, value in context_layer.items(): - # Replace any request elements - they have a large - # unicode representation and the request data is - # already made available from the Request Vars panel. - if isinstance(value, http.HttpRequest): - context_layer[key] = '<>' - # Replace the debugging sql_queries element. The SQL - # data is already made available from the SQL panel. - elif key == 'sql_queries' and isinstance(value, list): - context_layer[key] = '<>' - # Replace LANGUAGES, which is available in i18n context processor - elif key == 'LANGUAGES' and isinstance(value, tuple): - context_layer[key] = '<>' - try: - context_list.append(pformat(context_layer)) - except UnicodeEncodeError: - pass + context_list = template_data.get('context', []) info['context'] = '\n'.join(context_list) template_context.append(info) diff --git a/example/example.db b/example/example.db index 1339622..e0048d8 100644 Binary files a/example/example.db and b/example/example.db differ -- cgit v1.2.3