diff options
| -rw-r--r-- | debug_toolbar/panels/__init__.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/static/debug_toolbar/js/toolbar.js | 17 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/base.html | 13 | ||||
| -rw-r--r-- | debug_toolbar/toolbar/loader.py | 23 | ||||
| -rw-r--r-- | debug_toolbar/urls.py | 1 | ||||
| -rw-r--r-- | 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 = '<div class="djDebugPanelTitle"><a class="djDebugClose djDebugBack" href="">Back</a><h3>'+xhr.status+': '+xhr.statusText+'</h3></div>'; +                            $('#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('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar  //]]></script>  <script src="{{ STATIC_URL }}debug_toolbar/js/jquery.cookie.js"></script>  <script src="{{ STATIC_URL }}debug_toolbar/js/toolbar.js"></script> -<div id="djDebug" style="display:none;" dir="ltr" {{ TOOLBAR_ROOT_TAG_ATTRS|safe }}> +<div id="djDebug" style="display:none;" dir="ltr" +     data-toolbar-id="{{ toolbar_id }}" data-render-panel-url="/__debug__/render_panel/" +     {{ TOOLBAR_ROOT_TAG_ATTRS|safe }}>  	<div style="display:none;" id="djDebugToolbar">  		<ul id="djDebugPanelList">  			{% if panels %} @@ -22,7 +24,7 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar  					{% if panel.has_content and panel.enabled %}  						<a href="{{ panel.url|default:"#" }}" title="{{ panel.title }}" class="{{ panel.dom_id }}">  					{% else %} -					    <div class="contentless{% if panel.disabled %} disabled{% endif %}"> +						<div class="contentless{% if panel.disabled %} disabled{% endif %}">  					{% endif %}  					{{ panel.nav_title }}  					{% if panel.enabled %} @@ -33,7 +35,7 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar  					{% if panel.has_content and panel.enabled %}  						</a>  					{% else %} -					    </div> +						</div>  					{% endif %}  				</li>  			{% endfor %} @@ -50,9 +52,8 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar  					<h3>{{ panel.title|safe }}</h3>  				</div>  				<div class="djDebugPanelContent"> -				    <div class="scroll"> -				        {{ panel.content|safe }} -				    </div> +					<div class="scroll"> +					</div>  				</div>  			</div>  		{% endif %} diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index 7b525b6..de4aa93 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -46,7 +46,6 @@ class DebugToolbar(object):          global panel_classes          for panel_class in panel_classes:              panel_instance = panel_class(self, context=self.template_context) -              self._panels[panel_class] = panel_instance      def render_toolbar(self): @@ -56,8 +55,8 @@ class DebugToolbar(object):          context = self.template_context.copy()          context.update({              'panels': self.panels, +            'toolbar_id': save_toolbar(self),          }) -          return render_to_string('debug_toolbar/base.html', context) @@ -101,3 +100,23 @@ def load_panel_classes():                  'Toolbar Panel module "%s" does not define a "%s" class' %                  (panel_module, panel_classname))          panel_classes.append(panel_class) + + +toolbar_counter = 0 +toolbar_maxsize = 10            # keep data for the last 10 requests +toolbar_results = SortedDict() + + +def save_toolbar(toolbar): +    global toolbar_counter, toolbar_results +    toolbar_counter += 1 +    toolbar_results[toolbar_counter] = toolbar +    for _ in range(len(toolbar_results) - toolbar_maxsize): +        # When we drop support for Python 2.6 and switch to +        # collections.OrderedDict, use popitem(last=False). +        del toolbar_results[toolbar_results.keyOrder[0]] +    return toolbar_counter + + +def get_saved_toolbar(toolbar_id): +    return toolbar_results.get(toolbar_id) diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py index 1a6daf8..05ef245 100644 --- a/debug_toolbar/urls.py +++ b/debug_toolbar/urls.py @@ -12,6 +12,7 @@ from django.conf.urls import patterns, url  _PREFIX = '__debug__'  urlpatterns = patterns('debug_toolbar.views',                           # noqa +    url(r'^%s/render_panel/$' % _PREFIX, 'render_panel', name='render_panel'),      url(r'^%s/sql_select/$' % _PREFIX, 'sql_select', name='sql_select'),      url(r'^%s/sql_explain/$' % _PREFIX, 'sql_explain', name='sql_explain'),      url(r'^%s/sql_profile/$' % _PREFIX, 'sql_profile', name='sql_profile'), diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index 8b3e63c..21f4747 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -6,11 +6,30 @@ views in any other way is generally not advised.  from __future__ import unicode_literals -from django.http import HttpResponseBadRequest +from django.http import HttpResponse, HttpResponseBadRequest  from django.shortcuts import render +from django.utils.html import escape +from django.utils.translation import ugettext as _  from django.views.decorators.csrf import csrf_exempt  from debug_toolbar.forms import SQLSelectForm +from debug_toolbar.toolbar.loader import get_saved_toolbar + + +def render_panel(request): +    """Render the contents of a panel""" +    toolbar = get_saved_toolbar(int(request.GET['toolbar_id'])) +    if toolbar is None: +        content = _("Data for this panel isn't available anymore. " +                    "Please reload the page and retry.") +        content = "<p>%s</p>" % escape(content) +    else: +        panel_id = request.GET['panel_id'] +        for panel in toolbar.panels: +            if panel.dom_id() == panel_id: +                content = panel.content() +                break +    return HttpResponse(content)  @csrf_exempt | 
