diff options
| author | Aymeric Augustin | 2013-11-09 19:07:38 +0100 | 
|---|---|---|
| committer | Aymeric Augustin | 2013-11-10 10:39:42 +0100 | 
| commit | 2816c6fa2a1613e5eeb7967cde0793019ce62feb (patch) | |
| tree | 2aaff3c512dd78f9686a81f626cba9702a3bd157 /debug_toolbar/views.py | |
| parent | 631bbd18c10f572e31ef30f4dc78df942beeffd4 (diff) | |
| download | django-debug-toolbar-2816c6fa2a1613e5eeb7967cde0793019ce62feb.tar.bz2 | |
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.
Diffstat (limited to 'debug_toolbar/views.py')
| -rw-r--r-- | debug_toolbar/views.py | 21 | 
1 files changed, 20 insertions, 1 deletions
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  | 
