+
+
{% for panel in panels %}
{% if panel.has_content %}
--
cgit v1.2.3
From 184277b5d9a4658eb326d8f679618284299554a2 Mon Sep 17 00:00:00 2001
From: Reto Aebersold
Date: Sat, 17 Jan 2009 12:21:27 -0800
Subject: Fixing AJAX calls to detailed SQL views.
Signed-off-by: Rob Hudson
---
debug_toolbar/middleware.py | 4 +++-
debug_toolbar/urls.py | 12 +++++++-----
debug_toolbar/views.py | 17 +++++++++++++----
3 files changed, 23 insertions(+), 10 deletions(-)
(limited to 'debug_toolbar')
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 8dcf454..c3cf5f9 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -8,6 +8,8 @@ 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')
@@ -37,7 +39,7 @@ class DebugToolbarMiddleware(object):
def show_toolbar(self, request):
if not settings.DEBUG:
return False
- if request.is_ajax():
+ 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 not request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
return False
diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py
index 77d1a80..05233e2 100644
--- a/debug_toolbar/urls.py
+++ b/debug_toolbar/urls.py
@@ -7,10 +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__'
+
urlpatterns = patterns('',
- url(r'^__debug__/m/(.*)$', 'debug_toolbar.views.debug_media'),
- url(r'^__debug__/sql_select/$', 'debug_toolbar.views.sql_select', name='sql_select'),
- url(r'^__debug__/sql_explain/$', 'debug_toolbar.views.sql_explain', name='sql_explain'),
- url(r'^__debug__/sql_profile/$', 'debug_toolbar.views.sql_profile', name='sql_profile'),
- url(r'^__debug__/template_source/$', 'debug_toolbar.views.template_source', name='template_source'),
+ 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'),
)
diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py
index e3bb5b1..0fb4168 100644
--- a/debug_toolbar/views.py
+++ b/debug_toolbar/views.py
@@ -8,11 +8,17 @@ import os
import django.views.static
from django.conf import settings
from django.db import connection
-from django.http import HttpResponse, HttpResponseBadRequest
+from django.http import HttpResponseBadRequest
from django.shortcuts import render_to_response
from django.utils import simplejson
from django.utils.hashcompat import sha_constructor
+class InvalidSQLError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
+
def debug_media(request, path):
root = getattr(settings, 'DEBUG_TOOLBAR_MEDIA_ROOT', None)
if root is None:
@@ -36,7 +42,7 @@ def sql_select(request):
hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
- if sql.lower().startswith('select'):
+ if sql.lower().strip().startswith('select'):
params = simplejson.loads(params)
cursor = connection.cursor()
cursor.execute(sql, params)
@@ -50,6 +56,7 @@ def sql_select(request):
'headers': headers,
}
return render_to_response('debug_toolbar/panels/sql_select.html', context)
+ raise InvalidSQLError("Only 'select' queries are allowed.")
def sql_explain(request):
"""
@@ -67,7 +74,7 @@ def sql_explain(request):
hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
- if sql.lower().startswith('select'):
+ if sql.lower().strip().startswith('select'):
params = simplejson.loads(params)
cursor = connection.cursor()
cursor.execute("EXPLAIN %s" % (sql,), params)
@@ -81,6 +88,7 @@ def sql_explain(request):
'headers': headers,
}
return render_to_response('debug_toolbar/panels/sql_explain.html', context)
+ raise InvalidSQLError("Only 'select' queries are allowed.")
def sql_profile(request):
"""
@@ -98,7 +106,7 @@ def sql_profile(request):
hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
- if sql.lower().startswith('select'):
+ if sql.lower().strip().startswith('select'):
params = simplejson.loads(params)
cursor = connection.cursor()
cursor.execute("SET PROFILING=1") # Enable profiling
@@ -116,6 +124,7 @@ def sql_profile(request):
'headers': headers,
}
return render_to_response('debug_toolbar/panels/sql_explain.html', context)
+ raise InvalidSQLError("Only 'select' queries are allowed.")
def template_source(request):
"""
--
cgit v1.2.3
From 87754fba031019d9fcff25c5dba2563baeb7ea1b Mon Sep 17 00:00:00 2001
From: Rob Hudson
Date: Sat, 17 Jan 2009 12:23:42 -0800
Subject: Minor stylistic changes to CSS and Javascript file after merge.
---
debug_toolbar/media/toolbar.css | 10 +++++-----
debug_toolbar/media/toolbar.js | 16 +++++++++++-----
2 files changed, 16 insertions(+), 10 deletions(-)
(limited to 'debug_toolbar')
diff --git a/debug_toolbar/media/toolbar.css b/debug_toolbar/media/toolbar.css
index a04f451..4800157 100644
--- a/debug_toolbar/media/toolbar.css
+++ b/debug_toolbar/media/toolbar.css
@@ -35,13 +35,13 @@
width: 16px;
}
-#djDebugToolbarHandle ul li{
- padding: 3px 0px 0px 3px;
+#djDebugToolbarHandle ul li {
+ padding: 3px 0px 0px 3px;
}
-#djDebugToolbarHandle ul li a{
- font-size: 16px;
- font-weight: bold;
+#djDebugToolbarHandle ul li a {
+ font-size: 16px;
+ font-weight: bold;
}
#djDebugToolbar ul {
diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js
index dcd52ae..b6baa2c 100644
--- a/debug_toolbar/media/toolbar.js
+++ b/debug_toolbar/media/toolbar.js
@@ -42,9 +42,9 @@ jQuery(function($) {
$('#djShowToolBarButton').click(function() {
$.djDebug.show_toolbar();
});
- if($.cookie(COOKIE_NAME)){
+ if ($.cookie(COOKIE_NAME)) {
$.djDebug.hide_toolbar(false);
- }else{
+ } else {
$('#djDebugToolbar').show();
}
},
@@ -69,14 +69,20 @@ jQuery(function($) {
hide_toolbar: function(setCookie) {
$('#djDebugToolbar').hide("fast");
$('#djDebugToolbarHandle').show();
- if(setCookie){
- $.cookie(COOKIE_NAME, 'hide', {path: '/', expires: 10 });
+ if (setCookie) {
+ $.cookie(COOKIE_NAME, 'hide', {
+ path: '/',
+ expires: 10
+ });
}
},
show_toolbar: function() {
$('#djDebugToolbarHandle').hide();
$('#djDebugToolbar').show("fast");
- $.cookie(COOKIE_NAME, null, {path: '/', expires: -1 });
+ $.cookie(COOKIE_NAME, null, {
+ path: '/',
+ expires: -1
+ });
}
});
$(document).bind('close.djDebug', function() {
--
cgit v1.2.3
From a51c3a5bba2e0d0e7046cd7eaee86ac01cf097d8 Mon Sep 17 00:00:00 2001
From: Reto Aebersold
Date: Thu, 15 Jan 2009 09:51:31 +0100
Subject: added missing jquery cookie plugin files
Signed-off-by: Rob Hudson
---
debug_toolbar/media/jquery.cookie.js | 96 ++++++++++++++++++++++++++++++++
debug_toolbar/media/jquery.cookie.min.js | 1 +
2 files changed, 97 insertions(+)
create mode 100644 debug_toolbar/media/jquery.cookie.js
create mode 100644 debug_toolbar/media/jquery.cookie.min.js
(limited to 'debug_toolbar')
diff --git a/debug_toolbar/media/jquery.cookie.js b/debug_toolbar/media/jquery.cookie.js
new file mode 100644
index 0000000..6df1fac
--- /dev/null
+++ b/debug_toolbar/media/jquery.cookie.js
@@ -0,0 +1,96 @@
+/**
+ * Cookie plugin
+ *
+ * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ */
+
+/**
+ * Create a cookie with the given name and value and other optional parameters.
+ *
+ * @example $.cookie('the_cookie', 'the_value');
+ * @desc Set the value of a cookie.
+ * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
+ * @desc Create a cookie with all available options.
+ * @example $.cookie('the_cookie', 'the_value');
+ * @desc Create a session cookie.
+ * @example $.cookie('the_cookie', null);
+ * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
+ * used when the cookie was set.
+ *
+ * @param String name The name of the cookie.
+ * @param String value The value of the cookie.
+ * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
+ * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
+ * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
+ * If set to null or omitted, the cookie will be a session cookie and will not be retained
+ * when the the browser exits.
+ * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
+ * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
+ * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
+ * require a secure protocol (like HTTPS).
+ * @type undefined
+ *
+ * @name $.cookie
+ * @cat Plugins/Cookie
+ * @author Klaus Hartl/klaus.hartl@stilbuero.de
+ */
+
+/**
+ * Get the value of a cookie with the given name.
+ *
+ * @example $.cookie('the_cookie');
+ * @desc Get the value of a cookie.
+ *
+ * @param String name The name of the cookie.
+ * @return The value of the cookie.
+ * @type String
+ *
+ * @name $.cookie
+ * @cat Plugins/Cookie
+ * @author Klaus Hartl/klaus.hartl@stilbuero.de
+ */
+jQuery.cookie = function(name, value, options) {
+ if (typeof value != 'undefined') { // name and value given, set cookie
+ options = options || {};
+ if (value === null) {
+ value = '';
+ options.expires = -1;
+ }
+ var expires = '';
+ if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
+ var date;
+ if (typeof options.expires == 'number') {
+ date = new Date();
+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
+ } else {
+ date = options.expires;
+ }
+ expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
+ }
+ // CAUTION: Needed to parenthesize options.path and options.domain
+ // in the following expressions, otherwise they evaluate to undefined
+ // in the packed version for some reason...
+ var path = options.path ? '; path=' + (options.path) : '';
+ var domain = options.domain ? '; domain=' + (options.domain) : '';
+ var secure = options.secure ? '; secure' : '';
+ document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
+ } else { // only name given, get cookie
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+};
\ No newline at end of file
diff --git a/debug_toolbar/media/jquery.cookie.min.js b/debug_toolbar/media/jquery.cookie.min.js
new file mode 100644
index 0000000..eb129db
--- /dev/null
+++ b/debug_toolbar/media/jquery.cookie.min.js
@@ -0,0 +1 @@
+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 toolbar.min.js
- java -jar ~/bin/yuicompressor.jar jquery.cookie.js > jquery.cookie.min.js
+ java -jar ~/bin/yuicompressor.jar jquery.cookie.js >> toolbar.min.js
compress_css:
java -jar ~/bin/yuicompressor.jar --type css toolbar.css > toolbar.min.css
diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html
index 3b8e92e..7277620 100644
--- a/debug_toolbar/templates/debug_toolbar/base.html
+++ b/debug_toolbar/templates/debug_toolbar/base.html
@@ -4,7 +4,6 @@
document.write(unescape('%3Cscript src="' + jquery_url + '" type="text/javascript"%3E%3C/script%3E'));
}
-