aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.rst44
-rw-r--r--debug_toolbar/media/toolbar.js8
-rw-r--r--debug_toolbar/media/toolbar.min.js2
-rw-r--r--debug_toolbar/middleware.py21
-rw-r--r--debug_toolbar/templates/debug_toolbar/base.html7
-rw-r--r--debug_toolbar/urls.py12
6 files changed, 75 insertions, 19 deletions
diff --git a/README.rst b/README.rst
index 2236ba4..068fea2 100644
--- a/README.rst
+++ b/README.rst
@@ -36,17 +36,30 @@ Installation
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
+ response is either `text/html` or `application/xhtml+xml` and contains a
+ closing `</body>` tag.
+
#. Make sure your IP is listed in the `INTERNAL_IPS` setting. If you are
working locally this will be:
INTERNAL_IPS = ('127.0.0.1',)
+ Note: This is required because of the built-in requirements of the
+ `show_toolbar` method. See below for how to define a method to determine
+ your own logic for displaying the toolbar.
+
#. Add `debug_toolbar` to your `INSTALLED_APPS` setting so Django can find the
template files associated with the Debug Toolbar.
Alternatively, add the path to the debug toolbar templates
(``'path/to/debug_toolbar/templates'`` to your ``TEMPLATE_DIRS`` setting.)
+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`
@@ -65,8 +78,35 @@ Installation
)
You can change the ordering of this tuple to customize the order of the
- panels you want to display. And you can include panels that you have created
- or that are specific to your project.
+ panels you want to display, or add/remove panels. If you have custom panels
+ you can include them in this way -- just provide the full Python path to
+ your panel.
+
+#. Optional: There are a few configuration options to the debug toolbar that
+ can be placed in a dictionary:
+
+ * `INTERCEPT_REDIRECTS`: If set to True (default), the debug toolbar will
+ show an intermediate page upon redirect so you can view any debug
+ information prior to redirecting. This page will provide a link to the
+ redirect destination you can follow when ready. If set to False, redirects
+ will proceed as normal.
+
+ * `SHOW_TOOLBAR_CALLBACK`: If not set or set to None, the debug_toolbar
+ middleware will use its built-in show_toolbar method for determining whether
+ the toolbar should show or not. The default checks are that DEBUG must be
+ set to True and the IP of the request must be in INTERNAL_IPS. You can
+ provide your own method for displaying the toolbar which contains your
+ custom logic. This method should return True or False.
+
+ 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,
+ }
TODOs and BUGS
==============
diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js
index c69a917..40e1a58 100644
--- a/debug_toolbar/media/toolbar.js
+++ b/debug_toolbar/media/toolbar.js
@@ -1,6 +1,5 @@
-var _$ = window.$;
-$j = jQuery.noConflict();
-jQuery(function() {
+jQuery.noConflict();
+jQuery(function($j) {
var COOKIE_NAME = 'dj_debug_panel';
$j.djDebug = function(data, klass) {
$j.djDebug.init();
@@ -78,6 +77,7 @@ jQuery(function() {
},
hide_toolbar: function(setCookie) {
$j('#djDebugToolbar').hide("fast");
+ $j(document).trigger('close.djDebug');
$j('#djDebugToolbarHandle').show();
if (setCookie) {
$j.cookie(COOKIE_NAME, 'hide', {
@@ -103,5 +103,3 @@ jQuery(function() {
jQuery(function() {
jQuery.djDebug();
});
-$ = _$;
-
diff --git a/debug_toolbar/media/toolbar.min.js b/debug_toolbar/media/toolbar.min.js
index 4c967f8..7f8658f 100644
--- a/debug_toolbar/media/toolbar.min.js
+++ b/debug_toolbar/media/toolbar.min.js
@@ -1 +1 @@
-var _$=window.$;$j=jQuery.noConflict();jQuery(function(){var a="dj_debug_panel";$j.djDebug=function(c,b){$j.djDebug.init()};$j.extend($j.djDebug,{init:function(){var b=null;$j("#djDebugPanelList li a").click(function(){if(!this.className){return false}b=$j("#djDebug #"+this.className);if(b.is(":visible")){$j(document).trigger("close.djDebug")}else{$j(".panelContent").hide();b.show();$j.djDebug.open()}return false});$j("#djDebug a.close").click(function(){$j(document).trigger("close.djDebug");return false});$j("#djDebug a.remoteCall").click(function(){$j("#djDebugWindow").load(this.href,{},function(){$j("#djDebugWindow a.back").click(function(){$j(this).parent().hide();return false})});$j("#djDebugWindow").show();return false});$j("#djDebugTemplatePanel a.djTemplateShowContext").click(function(){$j.djDebug.toggle_content($j(this).parent().next());return false});$j("#djDebugSQLPanel a.djSQLShowStacktrace").click(function(){$j.djDebug.toggle_content($j(this).parent().next());return false});$j("#djHideToolBarButton").click(function(){$j.djDebug.hide_toolbar(true);return false});$j("#djShowToolBarButton").click(function(){$j.djDebug.show_toolbar();return false});if($j.cookie(a)){$j.djDebug.hide_toolbar(false)}else{$j("#djDebugToolbar").show()}},open:function(){$j(document).bind("keydown.djDebug",function(b){if(b.keyCode==27){$j.djDebug.close()}})},toggle_content:function(b){if(b.is(":visible")){b.hide()}else{b.show()}},close:function(){$j(document).trigger("close.djDebug");return false},hide_toolbar:function(b){$j("#djDebugToolbar").hide("fast");$j("#djDebugToolbarHandle").show();if(b){$j.cookie(a,"hide",{path:"/",expires:10})}},show_toolbar:function(){$j("#djDebugToolbarHandle").hide();$j("#djDebugToolbar").show("fast");$j.cookie(a,null,{path:"/",expires:-1})}});$j(document).bind("close.djDebug",function(){$j(document).unbind("keydown.djDebug");$j(".panelContent").hide()})});jQuery(function(){jQuery.djDebug()});$=_$;jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}}; \ No newline at end of file
+jQuery.noConflict();jQuery(function(b){var a="dj_debug_panel";b.djDebug=function(d,c){b.djDebug.init()};b.extend(b.djDebug,{init:function(){var c=null;b("#djDebugPanelList li a").click(function(){if(!this.className){return false}c=b("#djDebug #"+this.className);if(c.is(":visible")){b(document).trigger("close.djDebug")}else{b(".panelContent").hide();c.show();b.djDebug.open()}return false});b("#djDebug a.close").click(function(){b(document).trigger("close.djDebug");return false});b("#djDebug a.remoteCall").click(function(){b("#djDebugWindow").load(this.href,{},function(){b("#djDebugWindow a.back").click(function(){b(this).parent().hide();return false})});b("#djDebugWindow").show();return false});b("#djDebugTemplatePanel a.djTemplateShowContext").click(function(){b.djDebug.toggle_content(b(this).parent().next());return false});b("#djDebugSQLPanel a.djSQLShowStacktrace").click(function(){b.djDebug.toggle_content(b(this).parent().next());return false});b("#djHideToolBarButton").click(function(){b.djDebug.hide_toolbar(true);return false});b("#djShowToolBarButton").click(function(){b.djDebug.show_toolbar();return false});if(b.cookie(a)){b.djDebug.hide_toolbar(false)}else{b("#djDebugToolbar").show()}},open:function(){b(document).bind("keydown.djDebug",function(c){if(c.keyCode==27){b.djDebug.close()}})},toggle_content:function(c){if(c.is(":visible")){c.hide()}else{c.show()}},close:function(){b(document).trigger("close.djDebug");return false},hide_toolbar:function(c){b("#djDebugToolbar").hide("fast");b(document).trigger("close.djDebug");b("#djDebugToolbarHandle").show();if(c){b.cookie(a,"hide",{path:"/",expires:10})}},show_toolbar:function(){b("#djDebugToolbarHandle").hide();b("#djDebugToolbar").show("fast");b.cookie(a,null,{path:"/",expires:-1})}});b(document).bind("close.djDebug",function(){b(document).unbind("keydown.djDebug");b(".panelContent").hide()})});jQuery(function(){jQuery.djDebug()});jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}}; \ No newline at end of file
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 9c46079..e4d7494 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -1,15 +1,16 @@
"""
Debug Toolbar middleware
"""
+import os
+
from django.conf import settings
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.utils.encoding import smart_unicode
from django.conf.urls.defaults import include, patterns
+
import debug_toolbar.urls
from debug_toolbar.toolbar.loader import DebugToolbar
-from debug_toolbar.urls import DEBUG_TB_URL_PREFIX
-import os
_HTML_TYPES = ('text/html', 'application/xhtml+xml')
@@ -36,11 +37,21 @@ class DebugToolbarMiddleware(object):
self.original_pattern = patterns('', ('', include(self.original_urlconf)),)
self.override_url = True
- def show_toolbar(self, request):
+ # Set method to use to decide to show toolbar
+ self.show_toolbar = self._show_toolbar # default
+ if hasattr(settings, 'DEBUG_TOOLBAR_CONFIG'):
+ show_toolbar_callback = settings.DEBUG_TOOLBAR_CONFIG.get(
+ 'SHOW_TOOLBAR_CALLBACK', None)
+ if show_toolbar_callback:
+ self.show_toolbar = show_toolbar_callback
+
+ def _show_toolbar(self, request):
if not settings.DEBUG:
return False
- if request.is_ajax() and not request.path.startswith(os.path.join('/', DEBUG_TB_URL_PREFIX)): #Allow ajax requests from the debug toolbar
- return False
+ if request.is_ajax() and not \
+ request.path.startswith(os.path.join('/', debug_toolbar.urls._PREFIX)):
+ # Allow ajax requests from the debug toolbar
+ return False
if not request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
return False
return True
diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html
index 7277620..52b7a5b 100644
--- a/debug_toolbar/templates/debug_toolbar/base.html
+++ b/debug_toolbar/templates/debug_toolbar/base.html
@@ -1,10 +1,17 @@
<script type="text/javascript" charset="utf-8">
+ // When jQuery is sourced, it's going to overwrite whatever might be in the
+ // '$' variable, so store a reference of it in a temporary variable...
+ var _$ = window.$;
if (typeof jQuery == 'undefined') {
var jquery_url = '{{ BASE_URL }}/__debug__/m/jquery.js';
document.write(unescape('%3Cscript src="' + jquery_url + '" type="text/javascript"%3E%3C/script%3E'));
}
</script>
<script type="text/javascript" src="{{ BASE_URL }}/__debug__/m/toolbar.min.js"></script>
+<script type="text/javascript" charset="utf-8">
+ // Now that jQuery is done loading, put the '$' variable back to what it was...
+ var $ = _$;
+</script>
<style type="text/css">
@import url({{ BASE_URL }}/__debug__/m/toolbar.min.css);
</style>
diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py
index 05233e2..77491e3 100644
--- a/debug_toolbar/urls.py
+++ b/debug_toolbar/urls.py
@@ -7,12 +7,12 @@ this into the urlconf for the request.
from django.conf.urls.defaults import *
from django.conf import settings
-DEBUG_TB_URL_PREFIX = '__debug__'
+_PREFIX = '__debug__'
urlpatterns = patterns('',
- url(r'^%s/m/(.*)$' % DEBUG_TB_URL_PREFIX, 'debug_toolbar.views.debug_media'),
- url(r'^%s/sql_select/$' % DEBUG_TB_URL_PREFIX, 'debug_toolbar.views.sql_select', name='sql_select'),
- url(r'^%s/sql_explain/$' % DEBUG_TB_URL_PREFIX, 'debug_toolbar.views.sql_explain', name='sql_explain'),
- url(r'^%s/sql_profile/$' % DEBUG_TB_URL_PREFIX, 'debug_toolbar.views.sql_profile', name='sql_profile'),
- url(r'^%s/template_source/$' % DEBUG_TB_URL_PREFIX, 'debug_toolbar.views.template_source', name='template_source'),
+ url(r'^%s/m/(.*)$' % _PREFIX, 'debug_toolbar.views.debug_media'),
+ url(r'^%s/sql_select/$' % _PREFIX, 'debug_toolbar.views.sql_select', name='sql_select'),
+ url(r'^%s/sql_explain/$' % _PREFIX, 'debug_toolbar.views.sql_explain', name='sql_explain'),
+ url(r'^%s/sql_profile/$' % _PREFIX, 'debug_toolbar.views.sql_profile', name='sql_profile'),
+ url(r'^%s/template_source/$' % _PREFIX, 'debug_toolbar.views.template_source', name='template_source'),
)