aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--README.rst2
-rw-r--r--debug_toolbar/templates/debug_toolbar/base.html2
-rw-r--r--debug_toolbar/toolbar/loader.py3
-rw-r--r--debug_toolbar/urls.py5
-rw-r--r--debug_toolbar/utils/tracking/db.py31
-rw-r--r--debug_toolbar/views.py24
-rw-r--r--tests/urls.py7
8 files changed, 54 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index f140dd0..96eddf8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,10 @@
# Make file to compress and join all JS files
all: compress_js compress_css
+test:
+ pip install Django
+ python runtests.py
+
compress_js:
java -jar ~/bin/yuicompressor.jar debug_toolbar/static/debug_toolbar/js/jquery.js > debug_toolbar/static/debug_toolbar/js/toolbar.min.js
java -jar ~/bin/yuicompressor.jar debug_toolbar/static/debug_toolbar/js/toolbar.js >> debug_toolbar/static/debug_toolbar/js/toolbar.min.js
diff --git a/README.rst b/README.rst
index 17659f1..6cbac7d 100644
--- a/README.rst
+++ b/README.rst
@@ -120,7 +120,7 @@ The debug toolbar has two settings that can be set in ``settings.py``:
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 or the IP of the request must be in INTERNAL_IPS. You can
+ 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.
diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html
index 8e91f60..a790bd1 100644
--- a/debug_toolbar/templates/debug_toolbar/base.html
+++ b/debug_toolbar/templates/debug_toolbar/base.html
@@ -3,7 +3,7 @@
@media print { #djDebug {display:none;}}
</style>
<link rel="stylesheet" href="{{ STATIC_URL }}debug_toolbar/css/toolbar.min.css" type="text/css">
-<script type="text/javascript" src="{{ STATIC_URL }}debug_toolbar/css/toolbar.min.js"></script>
+<script type="text/javascript" src="{{ STATIC_URL }}debug_toolbar/js/toolbar.min.js"></script>
<div id="djDebug" style="display:none;" dir="ltr">
<div style="display:none;" id="djDebugToolbar">
<ul id="djDebugPanelList">
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py
index ac42f3b..5701118 100644
--- a/debug_toolbar/toolbar/loader.py
+++ b/debug_toolbar/toolbar/loader.py
@@ -26,6 +26,7 @@ class DebugToolbar(object):
self.template_context = {
'BASE_URL': base_url, # for backwards compatibility
'DEBUG_TOOLBAR_MEDIA_URL': self.config.get('MEDIA_URL'),
+ 'STATIC_URL': settings.STATIC_URL,
}
self.load_panels()
@@ -55,8 +56,6 @@ class DebugToolbar(object):
"""
Renders the overall Toolbar with panels inside.
"""
- media_path = os.path.join(os.path.dirname(__file__), os.pardir, 'media', 'debug_toolbar')
-
context = self.template_context.copy()
context.update({
'panels': self.panels,
diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py
index 1446d99..0053ae7 100644
--- a/debug_toolbar/urls.py
+++ b/debug_toolbar/urls.py
@@ -4,7 +4,10 @@ URLpatterns for the debug toolbar.
These should not be loaded explicitly; the debug toolbar middleware will patch
this into the urlconf for the request.
"""
-from django.conf.urls.defaults import *
+try:
+ from django.conf.urls import patterns, url
+except ImportError: # django < 1.4
+ from django.conf.urls.defaults import patterns, url
_PREFIX = '__debug__'
diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py
index 4d87090..b675227 100644
--- a/debug_toolbar/utils/tracking/db.py
+++ b/debug_toolbar/utils/tracking/db.py
@@ -5,13 +5,22 @@ from threading import local
from django.conf import settings
from django.template import Node
-from django.utils import simplejson
from django.utils.encoding import force_unicode, smart_str
-from django.utils.hashcompat import sha_constructor
from debug_toolbar.utils import ms_from_timedelta, tidy_stacktrace, \
get_template_info, get_stack
from debug_toolbar.utils.compat.db import connections
+
+try:
+ import json
+except ImportError: # python < 2.6
+ from django.utils import simplejson as json
+
+try:
+ from hashlib import sha1
+except ImportError: # python < 2.5
+ from django.utils.hashcompat import sha_constructor as sha1
+
# TODO:This should be set in the toolbar loader as a default and panels should
# get a copy of the toolbar object with access to its config dictionary
SQL_WARNING_THRESHOLD = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) \
@@ -82,8 +91,13 @@ class NormalCursorWrapper(object):
for key, value in params.iteritems())
return map(self._quote_expr, params)
+ def _decode(self, param):
+ try:
+ return force_unicode(param, strings_only=True)
+ except UnicodeDecodeError:
+ return '(encoded string)'
+
def execute(self, sql, params=()):
- __traceback_hide__ = True
start = datetime.now()
try:
return self.cursor.execute(sql, params)
@@ -98,10 +112,8 @@ class NormalCursorWrapper(object):
stacktrace = []
_params = ''
try:
- _params = simplejson.dumps(
- [force_unicode(x, strings_only=True) for x in params]
- )
- except TypeError:
+ _params = json.dumps(map(self._decode, params))
+ except Exception:
pass # object not JSON serializable
template_info = None
@@ -134,7 +146,7 @@ class NormalCursorWrapper(object):
'duration': duration,
'raw_sql': sql,
'params': _params,
- 'hash': sha_constructor(settings.SECRET_KEY \
+ 'hash': sha1(settings.SECRET_KEY \
+ smart_str(sql) \
+ _params).hexdigest(),
'stacktrace': stacktrace,
@@ -146,10 +158,11 @@ class NormalCursorWrapper(object):
}
if engine == 'psycopg2':
+ from psycopg2.extensions import TRANSACTION_STATUS_INERROR
params.update({
'trans_id': self.logger.get_transaction_id(alias),
'trans_status': conn.get_transaction_status(),
- 'iso_level': conn.isolation_level,
+ 'iso_level': conn.isolation_level if not conn.get_transaction_status() == TRANSACTION_STATUS_INERROR else "",
'encoding': conn.encoding,
})
diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py
index 759cb66..4b4ebc9 100644
--- a/debug_toolbar/views.py
+++ b/debug_toolbar/views.py
@@ -9,11 +9,19 @@ import django.views.static
from django.conf import settings
from django.http import HttpResponseBadRequest
from django.shortcuts import render_to_response
-from django.utils import simplejson
-from django.utils.hashcompat import sha_constructor
from debug_toolbar.utils.compat.db import connections
+try:
+ import json
+except ImportError: # python < 2.6
+ from django.utils import simplejson as json
+
+try:
+ from hashlib import sha1
+except ImportError: # python < 2.5
+ from django.utils.hashcompat import sha_constructor as sha1
+
class InvalidSQLError(Exception):
def __init__(self, value):
@@ -37,11 +45,11 @@ def sql_select(request):
sql = request.GET.get('sql', '')
params = request.GET.get('params', '')
alias = request.GET.get('alias', 'default')
- hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
+ hash = sha1(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
if sql.lower().strip().startswith('select'):
- params = simplejson.loads(params)
+ params = json.loads(params)
cursor = connections[alias].cursor()
cursor.execute(sql, params)
headers = [d[0] for d in cursor.description]
@@ -72,11 +80,11 @@ def sql_explain(request):
sql = request.GET.get('sql', '')
params = request.GET.get('params', '')
alias = request.GET.get('alias', 'default')
- hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
+ hash = sha1(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
if sql.lower().strip().startswith('select'):
- params = simplejson.loads(params)
+ params = json.loads(params)
cursor = connections[alias].cursor()
conn = connections[alias].connection
@@ -120,11 +128,11 @@ def sql_profile(request):
sql = request.GET.get('sql', '')
params = request.GET.get('params', '')
alias = request.GET.get('alias', 'default')
- hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
+ hash = sha1(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
if sql.lower().strip().startswith('select'):
- params = simplejson.loads(params)
+ params = json.loads(params)
cursor = connections[alias].cursor()
result = None
headers = None
diff --git a/tests/urls.py b/tests/urls.py
index a556703..778f417 100644
--- a/tests/urls.py
+++ b/tests/urls.py
@@ -4,14 +4,17 @@ URLpatterns for the debug toolbar.
These should not be loaded explicitly; the debug toolbar middleware will patch
this into the urlconf for the request.
"""
-from django.conf.urls.defaults import *
from django.contrib import admin
+try:
+ from django.conf.urls import patterns, url
+except ImportError: # django < 1.4
+ from django.conf.urls.defaults import patterns, url
admin.autodiscover()
urlpatterns = patterns('',
# This pattern should be last to ensure tests still work
- url(r'^resolving1/(.+)/(.+)/$', 'tests.views.resolving_view', name = 'positional-resolving'),
+ url(r'^resolving1/(.+)/(.+)/$', 'tests.views.resolving_view', name='positional-resolving'),
url(r'^resolving2/(?P<arg1>.+)/(?P<arg2>.+)/$', 'tests.views.resolving_view'),
url(r'^resolving3/(.+)/$', 'tests.views.resolving_view', { 'arg2' : 'default' }),
url(r'^execute_sql/$', 'tests.views.execute_sql'),