From 8cd6346f67448855c11161132995e467984a7247 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Tue, 30 Sep 2008 13:10:20 -0700 Subject: Removing unneeded check for toolbar that is taken care of a few lines up. --- debug_toolbar/middleware.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 6d2391c..44a8b9d 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -61,10 +61,9 @@ class DebugToolbarMiddleware(object): 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 - #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('' + self.debug_toolbar.render_toolbar()), response.content) - response.content = _END_BODY_RE.sub(smart_str(''), response.content) + if response['Content-Type'].split(';')[0] in _HTML_TYPES: + # Saving this here in case we ever need to inject into + #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('' + self.debug_toolbar.render_toolbar()), response.content) + response.content = _END_BODY_RE.sub(smart_str(''), response.content) return response -- cgit v1.2.3 From 005f67ebbc37dca871fc211e1fc46b9299e4787b Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Tue, 30 Sep 2008 13:22:17 -0700 Subject: Adding redirect interception to the middleware to be able to view debug info before being redirected to a new page. Thanks to [530] in IRC for the idea. Coming soon will be a way to optionally disable this. --- debug_toolbar/middleware.py | 9 +++++++++ debug_toolbar/templates/debug_toolbar/redirect.html | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 debug_toolbar/templates/debug_toolbar/redirect.html (limited to 'debug_toolbar') diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 44a8b9d..58712d9 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,6 +59,13 @@ class DebugToolbarMiddleware(object): def process_response(self, request, response): if not self.debug_toolbar: return response + 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: 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 @@ + + + + +

HttpResponseRedirect

+

Location: {{ redirect_to }}

+

+ 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 INTERCEPT_REDIRECTS to False. +

+ + -- cgit v1.2.3 From 51a79cfcb7d731f951647778d504a3e654d4883f Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Tue, 30 Sep 2008 14:08:47 -0700 Subject: Adding toolbar config to override INTERCEPT_REDIRECTS and, in the future, other configurable pieces of the toolbar. --- debug_toolbar/middleware.py | 15 ++++++++------- debug_toolbar/toolbar/loader.py | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 58712d9..140ceba 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -59,13 +59,14 @@ class DebugToolbarMiddleware(object): def process_response(self, request, response): if not self.debug_toolbar: return response - 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 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: 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: -- cgit v1.2.3