diff options
| author | Aymeric Augustin | 2013-11-16 09:47:14 +0100 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-16 10:10:09 +0100 |
| commit | 71a2c1237de8ed759c3ba415c8bfd91b62adf193 (patch) | |
| tree | 00bc509a00075a0a9266832ff054d9a2e80b9f6f /debug_toolbar/toolbar.py | |
| parent | 6334983458abd4380c21275d1229527778cf93a6 (diff) | |
| download | django-debug-toolbar-71a2c1237de8ed759c3ba415c8bfd91b62adf193.tar.bz2 | |
Clean up DebugToolbar class, especially panels handling.
Diffstat (limited to 'debug_toolbar/toolbar.py')
| -rw-r--r-- | debug_toolbar/toolbar.py | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index acb86d9..8b48a9f 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -29,28 +29,34 @@ class DebugToolbar(object): 'STATIC_URL': settings.STATIC_URL, 'TOOLBAR_ROOT_TAG_ATTRS': self.config['ROOT_TAG_ATTRS'], } - - self.load_panels() self.stats = {} + for panel_class in self.get_panel_classes(): + panel_instance = panel_class(self, context=self.template_context) + self._panels[panel_instance.panel_id] = panel_instance - def _get_panels(self): - return list(self._panels.values()) - panels = property(_get_panels) + # Manage panels - def _get_enabled_panels(self): - return [panel for panel in self._panels.values() if panel.enabled()] - enabled_panels = property(_get_enabled_panels) + @property + def panels(self): + """ + Get a list of all available panels. + """ + return list(self._panels.values()) - def get_panel(self, cls): - return self._panels[cls] + @property + def enabled_panels(self): + """ + Get a list of panels enabled for the current request. + """ + return [panel for panel in self._panels.values() if panel.enabled] - def load_panels(self): + def get_panel_by_id(self, panel_id): """ - Populate debug panels + Get the panel with the given id, which is the class name by default. """ - for panel_class in self.get_panel_classes(): - panel_instance = panel_class(self, context=self.template_context) - self._panels[panel_class] = panel_instance + return self._panels[panel_id] + + # Handle rendering the toolbar in HTML def render_toolbar(self): """ @@ -86,8 +92,8 @@ class DebugToolbar(object): def fetch(cls, storage_id): return cls._storage.get(storage_id) - # Manually implement class-level caching of the list of panels because - # it's more obvious than going through an abstraction. + # Manually implement class-level caching of panel classes and url patterns + # because it's more obvious than going through an abstraction. _panel_classes = None |
