From af4f7a99dc346bb6b844564370fd6d479d6c36e7 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 20 Sep 2008 20:18:41 +0100 Subject: Use $ shortcut for jQuery without conflicting with other libraries --- debug_toolbar/media/toolbar.js | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js index 3da65d2..b163000 100644 --- a/debug_toolbar/media/toolbar.js +++ b/debug_toolbar/media/toolbar.js @@ -1,34 +1,36 @@ jQuery.noConflict(); -jQuery(function() { - jQuery.djDebug = function(data, klass) { - jQuery.djDebug.init(); +jQuery(function($) { + $.djDebug = function(data, klass) { + $.djDebug.init(); } - jQuery.extend(jQuery.djDebug, { + $.extend($.djDebug, { init: function() { var current = null; - jQuery('#djDebugPanelList li a').click(function() { - current = jQuery('#djDebug #' + this.className); + $('#djDebugPanelList li a').click(function() { + current = $('#djDebug #' + this.className); if (current.is(':visible')) { - jQuery(document).trigger('close.djDebug'); + $(document).trigger('close.djDebug'); } else { - jQuery('.panelContent').hide(); + $('.panelContent').hide(); current.show(); - jQuery.djDebug.open(); + $.djDebug.open(); } return false; }); - jQuery('#djDebugTemplatePanel a.djTemplateShowContext').click(function() { - jQuery.djDebug.toggle_content(jQuery(this).parent().next()); - }); - jQuery('#djDebug a.close').click(function() { - jQuery(document).trigger('close.djDebug'); + $('#djDebugTemplatePanel a.djTemplateShowContext').click( + function() { + $.djDebug.toggle_content($(this).parent().next()); + } + ); + $('#djDebug a.close').click(function() { + $(document).trigger('close.djDebug'); return false; }); }, open: function() { - jQuery(document).bind('keydown.djDebug', function(e) { + $(document).bind('keydown.djDebug', function(e) { if (e.keyCode == 27) { - jQuery.djDebug.close(); + $.djDebug.close(); } }); }, @@ -40,16 +42,15 @@ jQuery(function() { } }, close: function() { - jQuery(document).trigger('close.djDebug'); + $(document).trigger('close.djDebug'); return false; } }); - jQuery(document).bind('close.djDebug', function() { - jQuery(document).unbind('keydown.djDebug'); - jQuery('.panelContent').hide(); + $(document).bind('close.djDebug', function() { + $(document).unbind('keydown.djDebug'); + $('.panelContent').hide(); }); }); - jQuery(function() { jQuery.djDebug(); }); -- cgit v1.2.3 From 8e124b0a129ab351ec6cae30d8358709d4c1430b Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 20 Sep 2008 20:30:45 +0100 Subject: Use pformat for template contexts, which makes it more readable --- debug_toolbar/panels/template.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index bda6630..e08f220 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -5,6 +5,8 @@ from django.template.loader import render_to_string from django.test.signals import template_rendered from debug_toolbar.panels import DebugPanel +from pprint import pformat + # Code taken and adapted from Simon Willison and Django Snippets: # http://www.djangosnippets.org/snippets/766/ @@ -60,7 +62,7 @@ class TemplateDebugPanel(DebugPanel): info['template'] = t # Clean up context for better readability c = d.get('context', None) - info['context'] = '\n'.join([_d.__repr__() for _d in c.dicts]) + info['context'] = '\n'.join([pformat(_d) for _d in c.dicts]) template_context.append(info) context = { 'templates': template_context, -- cgit v1.2.3 From 251a7f4eb5efaf6339edd57021e5ce3d53a679b3 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Sat, 20 Sep 2008 13:46:44 -0700 Subject: Import simplejson from django rather than an external dependency. --- debug_toolbar/panels/sql.py | 2 +- debug_toolbar/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 757505a..cdcbd1b 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -1,9 +1,9 @@ -import simplejson import time from debug_toolbar.panels import DebugPanel from django.db import connection from django.db.backends import util from django.template.loader import render_to_string +from django.utils import simplejson class DatabaseStatTracker(util.CursorDebugWrapper): """ diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index 1b44ed1..97739e6 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -5,11 +5,11 @@ views in any other way is generally not advised. """ import os -import simplejson import django.views.static from django.conf import settings from django.db import connection from django.shortcuts import render_to_response +from django.utils import simplejson def debug_media(request, path): root = getattr(settings, 'DEBUG_TOOLBAR_MEDIA_ROOT', None) -- cgit v1.2.3 From d85426c65e906d721e6b656ea9d7d53052c8a6bc Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Sat, 20 Sep 2008 15:37:19 -0700 Subject: From Simon Willison but cleaned up tabbing: Use $ shortcut for jQuery without conflicting with other libraries --- debug_toolbar/media/toolbar.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js index 3da65d2..0b3624b 100644 --- a/debug_toolbar/media/toolbar.js +++ b/debug_toolbar/media/toolbar.js @@ -1,34 +1,34 @@ jQuery.noConflict(); -jQuery(function() { - jQuery.djDebug = function(data, klass) { - jQuery.djDebug.init(); +jQuery(function($) { + $.djDebug = function(data, klass) { + $.djDebug.init(); } - jQuery.extend(jQuery.djDebug, { + $.extend($.djDebug, { init: function() { var current = null; - jQuery('#djDebugPanelList li a').click(function() { - current = jQuery('#djDebug #' + this.className); + $('#djDebugPanelList li a').click(function() { + current = $('#djDebug #' + this.className); if (current.is(':visible')) { - jQuery(document).trigger('close.djDebug'); + $(document).trigger('close.djDebug'); } else { - jQuery('.panelContent').hide(); + $('.panelContent').hide(); current.show(); - jQuery.djDebug.open(); + $.djDebug.open(); } return false; }); - jQuery('#djDebugTemplatePanel a.djTemplateShowContext').click(function() { - jQuery.djDebug.toggle_content(jQuery(this).parent().next()); + $('#djDebugTemplatePanel a.djTemplateShowContext').click(function() { + $.djDebug.toggle_content($(this).parent().next()); }); - jQuery('#djDebug a.close').click(function() { - jQuery(document).trigger('close.djDebug'); + $('#djDebug a.close').click(function() { + $(document).trigger('close.djDebug'); return false; }); }, open: function() { - jQuery(document).bind('keydown.djDebug', function(e) { + $(document).bind('keydown.djDebug', function(e) { if (e.keyCode == 27) { - jQuery.djDebug.close(); + $.djDebug.close(); } }); }, @@ -40,13 +40,13 @@ jQuery(function() { } }, close: function() { - jQuery(document).trigger('close.djDebug'); + $(document).trigger('close.djDebug'); return false; } }); - jQuery(document).bind('close.djDebug', function() { - jQuery(document).unbind('keydown.djDebug'); - jQuery('.panelContent').hide(); + $(document).bind('close.djDebug', function() { + $(document).unbind('keydown.djDebug'); + $('.panelContent').hide(); }); }); -- cgit v1.2.3