diff options
| author | Aymeric Augustin | 2013-11-13 20:40:22 +0100 | 
|---|---|---|
| committer | Aymeric Augustin | 2013-11-13 20:40:22 +0100 | 
| commit | 97090c32941784d28818721f37eee69e21e2d74e (patch) | |
| tree | fdabb0301faf9595312b908e738638d18ecffacb | |
| parent | a3acf6b57275f2a14cde7c209a8b6dff107275b0 (diff) | |
| download | django-debug-toolbar-97090c32941784d28818721f37eee69e21e2d74e.tar.bz2 | |
Provide an option to force rendering panels in page.
Requested by David who seems to runs the debug toolbar in production :-)
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/base.html | 1 | ||||
| -rw-r--r-- | debug_toolbar/toolbar.py | 13 | ||||
| -rw-r--r-- | debug_toolbar/utils/settings.py | 1 | ||||
| -rw-r--r-- | docs/configuration.rst | 14 | ||||
| -rw-r--r-- | docs/installation.rst | 5 | ||||
| -rw-r--r-- | tests/settings.py | 8 | 
6 files changed, 35 insertions, 7 deletions
| diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index c3cd339..b2ea63e 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -53,6 +53,7 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar  				</div>  				<div class="djDebugPanelContent">  					<div class="scroll"> +						{% if not storage_id %}{{ panel.content }}{% endif %}  					</div>  				</div>  			</div> diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index bf632cd..3f274d0 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -51,10 +51,9 @@ class DebugToolbar(object):          Renders the overall Toolbar with panels inside.          """          context = self.template_context.copy() -        context.update({ -            'panels': self.panels, -            'storage_id': self.store(), -        }) +        context['panels'] = self.panels +        if not self.should_render_panels(): +            context['storage_id'] = self.store()          return render_to_string('debug_toolbar/base.html', context)      # Handle storing toolbars in memory and fetching them later on @@ -62,6 +61,12 @@ class DebugToolbar(object):      _counter = 0      _storage = SortedDict() +    def should_render_panels(self): +        render_panels = dt_settings.CONFIG['RENDER_PANELS'] +        if render_panels is None: +            render_panels = self.request.META['wsgi.multiprocess'] +        return render_panels +      def store(self):          cls = type(self)          cls._counter += 1 diff --git a/debug_toolbar/utils/settings.py b/debug_toolbar/utils/settings.py index 45f661f..323e7cf 100644 --- a/debug_toolbar/utils/settings.py +++ b/debug_toolbar/utils/settings.py @@ -28,6 +28,7 @@ CONFIG_DEFAULTS = {      'ROOT_TAG_ATTRS': '',      'SQL_WARNING_THRESHOLD': 500,   # milliseconds      'RESULTS_CACHE_SIZE': 10, +    'RENDER_PANELS': None,  } diff --git a/docs/configuration.rst b/docs/configuration.rst index 129b0e0..d8cf9a9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -40,6 +40,20 @@ toolbar itself, others are specific to some panels.  Toolbar options  ~~~~~~~~~~~~~~~ +* ``RENDER_PANELS`` + +  Default: ``None`` + +  If set to ``False``, the debug toolbar will keep the contents of panels in +  memory on the server and load them on demand. If set to ``True``, it will +  render panels inside every page. This may slow down page rendering but it's +  required on multi-process servers, for example if you deploy the toolbar in +  production (which isn't recommended). + +  The default value of ``None`` tells the toolbar to automatically do the +  right thing depending on whether the WSGI container runs multiple processes. +  This setting allows you to force a different behavior if needed. +  * ``INTERCEPT_REDIRECTS``    Default: ``False`` diff --git a/docs/installation.rst b/docs/installation.rst index 3d71e12..5d046a2 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -41,9 +41,8 @@ what it does, or if you prefer defining your settings explicitly, read below.      The automatic setup relies on ``debug_toolbar.models`` being imported when      the server starts. Django doesn't provide a better hook to execute code -    during the start-up sequence. This works with Django's built-in -    development server ``runserver`` because it validates models before -    serving requests. You should use the explicit setup with other servers. +    during the start-up sequence. This works with ``manage.py runserver`` +    because it validates models before serving requests.  Explicit setup  -------------- diff --git a/tests/settings.py b/tests/settings.py index a41b5a7..4805cee 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -52,3 +52,11 @@ DATABASES = {          'ENGINE': 'django.db.backends.sqlite3',      }  } + + +# Debug Toolbar configuration + +DEBUG_TOOLBAR_CONFIG = { +    # Django's test client sets wsgi.multiprocess to True inappropriately +    'RENDER_PANELS': False, +} | 
