diff options
| author | Rob Hudson | 2009-09-12 16:55:15 -0700 | 
|---|---|---|
| committer | Rob Hudson | 2009-09-12 16:55:15 -0700 | 
| commit | 9801c8b0a312bd18ff20414d72bb5b5f9c941018 (patch) | |
| tree | 8032c47ff263cd6dc81aa9506140f001ea27a43f | |
| parent | b7d7e9f876b67be35d8a24405f6940b2dcb66e97 (diff) | |
| parent | d6190014abd950f032755fde33ce32c30fc0e754 (diff) | |
| download | django-debug-toolbar-9801c8b0a312bd18ff20414d72bb5b5f9c941018.tar.bz2 | |
Merge remote branch 'alex/master'
| -rw-r--r-- | README.rst | 23 | ||||
| -rw-r--r-- | debug_toolbar/panels/sql.py | 7 | ||||
| -rw-r--r-- | debug_toolbar/panels/template.py | 27 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/panels/templates.html | 2 | 
4 files changed, 38 insertions, 21 deletions
| @@ -3,7 +3,7 @@ Django Debug Toolbar  ====================  The Django Debug Toolbar is a configurable set of panels that display various -debug information about the current request/response and when clicked, display  +debug information about the current request/response and when clicked, display  more details about the panel's content.  Currently, the following panels have been written and are working: @@ -32,8 +32,8 @@ Installation     Tying into middleware allows each panel to be instantiated on request and     rendering to happen on response. -   The order of MIDDLEWARE_CLASSES is important: the Debug Toolbar middleware  -   must come after any other middleware that encodes the response's content  +   The order of MIDDLEWARE_CLASSES is important: the Debug Toolbar middleware +   must come after any other middleware that encodes the response's content     (such as GZipMiddleware).     Note: The debug toolbar will only display itself if the mimetype of the @@ -60,9 +60,9 @@ Configuration  The debug toolbar has two settings that can be set in `settings.py`: -#. Optional: Add a tuple called `DEBUG_TOOLBAR_PANELS` to your ``settings.py``  -   file that specifies the full Python path to the panel that you want included  -   in the Toolbar.  This setting looks very much like the `MIDDLEWARE_CLASSES`  +#. Optional: Add a tuple called `DEBUG_TOOLBAR_PANELS` to your ``settings.py`` +   file that specifies the full Python path to the panel that you want included +   in the Toolbar.  This setting looks very much like the `MIDDLEWARE_CLASSES`     setting.  For example::  	DEBUG_TOOLBAR_PANELS = ( @@ -101,15 +101,24 @@ The debug toolbar has two settings that can be set in `settings.py`:     * `EXTRA_SIGNALS`: An array of custom signals that might be in your project,       defined as the python path to the signal. +   * `HIDE_DJANGO_SQL`: If set to True (the default) then code in Django itself +     won't be shown in SQL stacktraces. + +   * `SHOW_TEMPLATE_CONTEXT`: If set to True (the default) then a template's +     context will be included with it in the Template debug panel.  Turning this +     off is useful when you have large template contexts, or you have template +     contexts with lazy datastructures that you don't want to be evaluated. +     Example configuration::  	def custom_show_toolbar(request):  	    return True # Always show toolbar, for example purposes only. -	 +  	DEBUG_TOOLBAR_CONFIG = {  	    'INTERCEPT_REDIRECTS': False,  	    'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,  	    'EXTRA_SIGNALS': ['myproject.signals.MySignal'], +	    'HIDE_DJANGO_SQL': False,  	}  TODOs and BUGS diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 17130ca..0c9bc61 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -1,7 +1,8 @@ +from datetime import datetime  import os  import SocketServer -from datetime import datetime  import traceback +  import django  from django.conf import settings  from django.db import connection @@ -10,6 +11,7 @@ from django.template.loader import render_to_string  from django.utils import simplejson  from django.utils.encoding import force_unicode  from django.utils.hashcompat import sha_constructor +  from debug_toolbar.panels import DebugPanel  # Figure out some paths @@ -71,7 +73,8 @@ def tidy_stacktrace(strace):      trace = []      for s in strace[:-1]:          s_path = os.path.realpath(s[0]) -        if django_path in s_path and not 'django/contrib' in s_path: +        if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) \ +            and django_path in s_path and not 'django/contrib' in s_path:              continue          if socketserver_path in s_path:              continue diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index 391902f..f090c78 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -37,16 +37,18 @@ class TemplateDebugPanel(DebugPanel):      def __init__(self):          self.templates = [] -        template_rendered.connect(self._storeTemplateInfo) +        template_rendered.connect(self._store_template_info) -    def _storeTemplateInfo(self, sender, **kwargs): +    def _store_template_info(self, sender, **kwargs):          self.templates.append(kwargs)      def nav_title(self):          return _('Templates')      def title(self): -        return 'Templates' +        num_templates = len([t for t in self.templates +            if not t['template'].name.startswith('debug_toolbar/')]) +        return 'Templates (%s rendered)' % num_templates      def url(self):          return '' @@ -75,15 +77,16 @@ class TemplateDebugPanel(DebugPanel):                  t.origin_name = 'No origin'              info['template'] = t              # Clean up context for better readability -            c = d.get('context', None) -             -            d_list = [] -            for _d in c.dicts: -                try: -                    d_list.append(pformat(d)) -                except UnicodeEncodeError: -                    pass -            info['context'] = '\n'.join(d_list) +            if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('SHOW_TEMPLATE_CONTEXT', True): +                c = d.get('context', None) + +                d_list = [] +                for _d in c.dicts: +                    try: +                        d_list.append(pformat(d)) +                    except UnicodeEncodeError: +                        pass +                info['context'] = '\n'.join(d_list)              template_context.append(info)          context = {              'templates': template_context, diff --git a/debug_toolbar/templates/debug_toolbar/panels/templates.html b/debug_toolbar/templates/debug_toolbar/panels/templates.html index 1158abe..6107876 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/templates.html +++ b/debug_toolbar/templates/debug_toolbar/panels/templates.html @@ -16,10 +16,12 @@  {% for template in templates %}  	<dt><strong><a class="remoteCall toggleTemplate" href="/__debug__/template_source/?template={{ template.template.name }}">{{ template.template.name|addslashes }}</a></strong></dt>  	<dd><samp>{{ template.template.origin_name|addslashes }}</samp></dd> +	{% if template.context %}  	<dd>  		<div class="djTemplateShowContextDiv"><a class="djTemplateShowContext"><span class="toggleArrow">▶</span> Toggle Context</a></div>  		<div class="djTemplateHideContextDiv" style="display:none;"><pre>{{ template.context }}</pre></div>  	</dd> +	{% endif %}  {% endfor %}  </dl>  {% else %} | 
