diff options
| author | Aymeric Augustin | 2013-11-10 01:45:30 -0800 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-10 01:45:30 -0800 |
| commit | 14245b5802d3a4b2a467c44b12a72a9d03722522 (patch) | |
| tree | b0ce5c782592b5a2a6b7188195dea5ecbdd064f8 /debug_toolbar/toolbar/loader.py | |
| parent | 0b4fc3e4c30a645e4d7a706d890c74a82c88cb8c (diff) | |
| parent | b61c85f2f03d2e879319b15af238f6ee34fbe1a4 (diff) | |
| download | django-debug-toolbar-14245b5802d3a4b2a467c44b12a72a9d03722522.tar.bz2 | |
Merge pull request #447 from aaugustin/load-panels-contents-on-demand
Load the content of panels dynamically
Diffstat (limited to 'debug_toolbar/toolbar/loader.py')
| -rw-r--r-- | debug_toolbar/toolbar/loader.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index c8630a9..de4aa93 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -45,8 +45,7 @@ class DebugToolbar(object): """ global panel_classes for panel_class in panel_classes: - panel_instance = panel_class(context=self.template_context) - + 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) |
