diff options
| author | David Cramer | 2011-07-12 13:08:40 -0700 |
|---|---|---|
| committer | David Cramer | 2011-07-12 13:08:40 -0700 |
| commit | ad110e020cbae062ba024d91223df519af3adc96 (patch) | |
| tree | 756bb0e665a60871db3b2e978f567da0a2438542 | |
| parent | a03b6a0cd04edb0bc387e46a9d51c5f18113da92 (diff) | |
| download | django-debug-toolbar-ad110e020cbae062ba024d91223df519af3adc96.tar.bz2 | |
Dont access __copy__ when it doesnt work. Preprocess context list so the dictionary cannot be modified.
| -rw-r--r-- | debug_toolbar/panels/template.py | 47 | ||||
| -rw-r--r-- | 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] = '<<request>>' + # 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] = '<<sql_queries>>' + # Replace LANGUAGES, which is available in i18n context processor + elif key == 'LANGUAGES' and isinstance(value, tuple): + context_layer[key] = '<<languages>>' + 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] = '<<request>>' - # 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] = '<<sql_queries>>' - # Replace LANGUAGES, which is available in i18n context processor - elif key == 'LANGUAGES' and isinstance(value, tuple): - context_layer[key] = '<<languages>>' - 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 Binary files differindex 1339622..e0048d8 100644 --- a/example/example.db +++ b/example/example.db |
