From 2816c6fa2a1613e5eeb7967cde0793019ce62feb Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 9 Nov 2013 19:07:38 +0100 Subject: Load the content of panels dynamically. This should drastically reduce the overhead of the browser toolbar when a page has a complex template structure or many SQL queries. This change is backwards-incompatible for third-party panels because it changes the signature of __init__. The JavaScript could probably be improved; I'm outside my comfort zone. --- debug_toolbar/panels/__init__.py | 2 +- debug_toolbar/static/debug_toolbar/js/toolbar.js | 17 +++++++++++++++++ debug_toolbar/templates/debug_toolbar/base.html | 13 +++++++------ debug_toolbar/toolbar/loader.py | 23 +++++++++++++++++++++-- debug_toolbar/urls.py | 1 + debug_toolbar/views.py | 21 ++++++++++++++++++++- 6 files changed, 67 insertions(+), 10 deletions(-) diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py index a48b1b3..c830bb2 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -11,7 +11,7 @@ class DebugPanel(object): """ # name = 'Base' # template = 'debug_toolbar/panels/base.html' - has_content = False # If content returns something, set to true in subclass + has_content = False # If content returns something, set to True in subclass # We'll maintain a local context instance so we can expose our template # context variables to panels which need them: diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 094c3ac..0b7d1ec 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -28,6 +28,23 @@ $(this).parent().removeClass('active'); } else { $('.panelContent').hide(); // Hide any that are already open + var inner = current.find('.djDebugPanelContent .scroll').first(); + if ($(inner).empty()) { + var ajax_data = { + data: { + toolbar_id: $('#djDebug').data('toolbar-id'), + panel_id: this.className + }, + type: 'GET', + url: $('#djDebug').data('render-panel-url') + }; + $.ajax(ajax_data).done(function(data){ + inner.html(data); + }).fail(function(xhr){ + var message = '
Back

'+xhr.status+': '+xhr.statusText+'

'; + $('#djDebugWindow').html(message).show(); + }); + } current.show(); $('#djDebugToolbar li').removeClass('active'); $(this).parent().addClass('active'); diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index e214044..d5a356c 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -8,7 +8,9 @@ if(!window.jQuery) document.write(' -