diff options
| author | Matt George | 2008-09-30 22:18:58 -0500 |
|---|---|---|
| committer | Matt George | 2008-09-30 22:18:58 -0500 |
| commit | bf6d1596e621c2e33468d2a36bb54f68c1baa205 (patch) | |
| tree | b3ba07823903beec0604d423c82abc7a9db98edc /debug_toolbar | |
| parent | 991969f4ab22fbf73bea2ec8d9afeba1962fa2a5 (diff) | |
| parent | 70278e8054dd0b0abb466d2fe7a043a10e871a37 (diff) | |
| download | django-debug-toolbar-bf6d1596e621c2e33468d2a36bb54f68c1baa205.tar.bz2 | |
Merge branch 'master' into session_panel
Diffstat (limited to 'debug_toolbar')
| -rw-r--r-- | debug_toolbar/middleware.py | 21 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/redirect.html | 14 | ||||
| -rw-r--r-- | debug_toolbar/toolbar/loader.py | 6 |
3 files changed, 35 insertions, 6 deletions
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 6d2391c..140ceba 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -3,6 +3,8 @@ Debug Toolbar middleware """ import re from django.conf import settings +from django.http import HttpResponseRedirect +from django.shortcuts import render_to_response from django.utils.encoding import smart_str from django.conf.urls.defaults import include, patterns import debug_toolbar.urls @@ -57,14 +59,21 @@ class DebugToolbarMiddleware(object): def process_response(self, request, response): if not self.debug_toolbar: return response + if self.debug_toolbar.config['INTERCEPT_REDIRECTS']: + if isinstance(response, HttpResponseRedirect): + redirect_to = response.get('Location', None) + if redirect_to: + response = render_to_response( + 'debug_toolbar/redirect.html', + {'redirect_to': redirect_to} + ) if response.status_code != 200: return response for panel in self.debug_toolbar.panels: panel.process_response(request, response) - if self.show_toolbar(request): - if response['Content-Type'].split(';')[0] in _HTML_TYPES: - # Saving this here in case we ever need to inject into <head> - #response.content = _END_HEAD_RE.sub(smart_str(self.debug_toolbar.render_styles() + "%s" % match.group()), response.content) - response.content = _START_BODY_RE.sub(smart_str('<body\\1>' + self.debug_toolbar.render_toolbar()), response.content) - response.content = _END_BODY_RE.sub(smart_str('<script src="' + request.META.get('SCRIPT_NAME', '') + '/__debug__/m/toolbar.js" type="text/javascript" charset="utf-8"></script></body>'), response.content) + if response['Content-Type'].split(';')[0] in _HTML_TYPES: + # Saving this here in case we ever need to inject into <head> + #response.content = _END_HEAD_RE.sub(smart_str(self.debug_toolbar.render_styles() + "%s" % match.group()), response.content) + response.content = _START_BODY_RE.sub(smart_str('<body\\1>' + self.debug_toolbar.render_toolbar()), response.content) + response.content = _END_BODY_RE.sub(smart_str('<script src="' + request.META.get('SCRIPT_NAME', '') + '/__debug__/m/toolbar.js" type="text/javascript" charset="utf-8"></script></body>'), response.content) return response diff --git a/debug_toolbar/templates/debug_toolbar/redirect.html b/debug_toolbar/templates/debug_toolbar/redirect.html new file mode 100644 index 0000000..b61286e --- /dev/null +++ b/debug_toolbar/templates/debug_toolbar/redirect.html @@ -0,0 +1,14 @@ +<html> +<head> +</head> +<body> +<h1>HttpResponseRedirect</h1> +<p>Location: <a href="{{ redirect_to }}">{{ redirect_to }}</a></p> +<p class="notice"> + The Django Debug Toolbar has intercepted a redirect to the above URL for + debug viewing purposes. You can click the above link to continue with the + redirect as normal. If you'd like to disable this feature, set the config + property <code>INTERCEPT_REDIRECTS</code> to <code>False</code>. +</p> +</body> +</html> diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index ce17080..29ab46e 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -8,6 +8,9 @@ class DebugToolbar(object): def __init__(self, request): self.request = request self.panels = [] + self.config = { + 'INTERCEPT_REDIRECTS': True, + } # Override this tuple by copying to settings.py as `DEBUG_TOOLBAR_PANELS` self.default_panels = ( 'debug_toolbar.panels.version.VersionDebugPanel', @@ -31,6 +34,9 @@ class DebugToolbar(object): # Check if settings has a DEBUG_TOOLBAR_PANELS, otherwise use default if hasattr(settings, 'DEBUG_TOOLBAR_PANELS'): self.default_panels = settings.DEBUG_TOOLBAR_PANELS + # Check if settings has a DEBUG_TOOLBAR_CONFIG and updated config + if hasattr(settings, 'DEBUG_TOOLBAR_CONFIG'): + self.config.update(settings.DEBUG_TOOLBAR_CONFIG) for panel_path in self.default_panels: try: |
