diff options
Diffstat (limited to 'debug_toolbar')
| -rw-r--r-- | debug_toolbar/static/debug_toolbar/js/toolbar.js | 2 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/base.html | 2 | ||||
| -rw-r--r-- | debug_toolbar/toolbar.py | 41 | ||||
| -rw-r--r-- | debug_toolbar/views.py | 4 |
4 files changed, 25 insertions, 24 deletions
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index add8298..9234c7c 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -31,7 +31,7 @@ if ($(inner).empty()) { var ajax_data = { data: { - toolbar_id: $('#djDebug').data('toolbar-id'), + storage_id: $('#djDebug').data('storage-id'), panel_id: this.className }, type: 'GET', diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index 4c82140..c3cd339 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -9,7 +9,7 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar <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" - data-toolbar-id="{{ toolbar_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}" + data-storage-id="{{ storage_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}" {{ TOOLBAR_ROOT_TAG_ATTRS|safe }}> <div style="display:none;" id="djDebugToolbar"> <ul id="djDebugPanelList"> diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index f9262f8..c0c210f 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -52,10 +52,30 @@ class DebugToolbar(object): context = self.template_context.copy() context.update({ 'panels': self.panels, - 'toolbar_id': save_toolbar(self), + 'storage_id': self.store(), }) return render_to_string('debug_toolbar/base.html', context) + # Handle storing toolbars in memory and fetching them later on + + _counter = 0 + _storage = SortedDict() + + def store(self): + cls = type(self) + cls._counter += 1 + cls._storage[cls._counter] = self + for _ in range(len(cls._storage) - CONFIG['RESULTS_CACHE_SIZE']): + # When we drop support for Python 2.6 and switch to + # collections.OrderedDict, use popitem(last=False). + del cls._storage[cls._storage.keyOrder[0]] + return cls._counter + + @classmethod + def fetch(cls, storage_id): + return cls._storage.get(storage_id) + + panel_classes = [] @@ -97,22 +117,3 @@ 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_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) - CONFIG['RESULTS_CACHE_SIZE']): - # 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/views.py b/debug_toolbar/views.py index 83432bf..841d04e 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -13,12 +13,12 @@ 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 import get_saved_toolbar +from debug_toolbar.toolbar import DebugToolbar def render_panel(request): """Render the contents of a panel""" - toolbar = get_saved_toolbar(int(request.GET['toolbar_id'])) + toolbar = DebugToolbar.fetch(int(request.GET['storage_id'])) if toolbar is None: content = _("Data for this panel isn't available anymore. " "Please reload the page and retry.") |
