aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/toolbar.py
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-12 21:48:42 +0100
committerAymeric Augustin2013-11-12 22:10:22 +0100
commitc1d50fc79645c71987ae156d371777dd371c422d (patch)
tree16bccc82c28a953a1321c685eaa7b0a5b94d3442 /debug_toolbar/toolbar.py
parent02716d9ca2728e33e92806f6ed0b3d9375df53a9 (diff)
downloaddjango-debug-toolbar-c1d50fc79645c71987ae156d371777dd371c422d.tar.bz2
Move store/fetch logic inside the DebugToolbar class.
Diffstat (limited to 'debug_toolbar/toolbar.py')
-rw-r--r--debug_toolbar/toolbar.py41
1 files changed, 21 insertions, 20 deletions
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)