diff options
| author | Rob Hudson | 2008-09-18 13:43:13 -0700 | 
|---|---|---|
| committer | Rob Hudson | 2008-09-18 13:43:13 -0700 | 
| commit | e40b2c0fbdbd932be5f9d0550a16b6652de0d38d (patch) | |
| tree | f26f3c7456c6f3c47cb168472f1994c449c24b60 /debug_toolbar | |
| parent | 816889b61cdd8bd1380009cfc755f9f655406e5c (diff) | |
| download | django-debug-toolbar-e40b2c0fbdbd932be5f9d0550a16b6652de0d38d.tar.bz2 | |
I noticed the template_rendered signal from the test suite also passed context,
so I'm including the context with each template in the Template panel.  This
should make the designers happy.
Diffstat (limited to 'debug_toolbar')
| -rw-r--r-- | debug_toolbar/media/toolbar.js | 10 | ||||
| -rw-r--r-- | debug_toolbar/panels/template.py | 28 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/panels/templates.html | 8 | 
3 files changed, 35 insertions, 11 deletions
diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js index e4e1ab3..21994a9 100644 --- a/debug_toolbar/media/toolbar.js +++ b/debug_toolbar/media/toolbar.js @@ -17,6 +17,9 @@ jQuery.noConflict();  				}  				return false;  			}); +			jQuery('#djDebugTemplatePanel a.djTemplateShowContext').click(function() { +				jQuery.djDebug.toggle_content(jQuery(this).parent().next()); +			});  			jQuery('#djDebug a.close').click(function() {  				jQuery(document).trigger('close.djDebug');  				return false; @@ -29,6 +32,13 @@ jQuery.noConflict();  				}  			});  		}, +		toggle_content: function(elem) { +			if (elem.is(':visible')) { +				elem.hide(); +			} else { +				elem.show(); +			} +		},  		close: function() {  			jQuery(document).trigger('close.djDebug');  			return false; diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index f1cf65b..f02b673 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -32,11 +32,11 @@ class TemplateDebugPanel(DebugPanel):      def __init__(self, request):          super(TemplateDebugPanel, self).__init__(request) -        self.templates_used = [] -        template_rendered.connect(self._storeRenderedTemplates) +        self.templates = [] +        template_rendered.connect(self._storeTemplateInfo) -    def _storeRenderedTemplates(self, sender, **kwargs): -        self.templates_used.append(kwargs['template']) +    def _storeTemplateInfo(self, sender, **kwargs): +        self.templates.append(kwargs)      def title(self):          return 'Templates' @@ -45,12 +45,22 @@ class TemplateDebugPanel(DebugPanel):          return ''      def content(self): -        templates = [ -            (t.name, t.origin and t.origin.name or 'No origin') -            for t in self.templates_used -        ] +        template_context = [] +        for i, d in enumerate(self.templates): +            info = {} +            # Clean up some info about templates +            t = d.get('template', None) +            if t.origin and t.origin.name: +                t.origin_name = t.origin.name +            else: +                t.origin_name = 'No origin' +            info['template'] = t +            # Clean up context for better readability +            c = d.get('context', None) +            info['context'] = '\n'.join([_d.__repr__() for _d in c.dicts]) +            template_context.append(info)          context = { -            'templates': templates, +            'templates': template_context,              'template_dirs': settings.TEMPLATE_DIRS,          }          return render_to_string('debug_toolbar/panels/templates.html', context) diff --git a/debug_toolbar/templates/debug_toolbar/panels/templates.html b/debug_toolbar/templates/debug_toolbar/panels/templates.html index f9f03b5..ee93708 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/templates.html +++ b/debug_toolbar/templates/debug_toolbar/panels/templates.html @@ -12,8 +12,12 @@  {% if templates %}  <dl>  {% for template in templates %} -	<dt><strong>{{ template.0|addslashes }}</strong></dt> -	<dd><samp>{{ template.1|addslashes }}</samp></dd> +	<dt><strong>{{ template.template.name|addslashes }}</strong></dt> +	<dd><samp>{{ template.template.origin_name|addslashes }}</samp></dd> +	<dd> +		<div class="djTemplateShowContextDiv"><a class="djTemplateShowContext">Toggle Context</a></div> +		<div class="djTemplateHideContextDiv" style="display:none;"><pre>{{ template.context }}</pre></div> +	</dd>  {% endfor %}  </dl>  {% else %}  | 
