diff options
| author | Jannis Leidel | 2012-03-31 17:11:11 +0200 |
|---|---|---|
| committer | Jannis Leidel | 2012-03-31 17:14:25 +0200 |
| commit | 2c7f68d55a6a0c101c41bd23ccb2d0ce9b332e42 (patch) | |
| tree | 5e93142d5fb3f464e50e36151c4c25d8347353e7 /debug_toolbar/toolbar/loader.py | |
| parent | 37a30194a1d5c9ebd7080954725dae38e19264fc (diff) | |
| download | django-debug-toolbar-2c7f68d55a6a0c101c41bd23ccb2d0ce9b332e42.tar.bz2 | |
Merge branch 'master' of https://github.com/ivirabyan/django-debug-toolbar into ivirabyan-master
Conflicts:
debug_toolbar/panels/cache.py
debug_toolbar/toolbar/loader.py
Diffstat (limited to 'debug_toolbar/toolbar/loader.py')
| -rw-r--r-- | debug_toolbar/toolbar/loader.py | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index a69c314..b2b9b20 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -26,19 +26,7 @@ class DebugToolbar(object): 'BASE_URL': base_url, # for backwards compatibility 'DEBUG_TOOLBAR_MEDIA_URL': self.config.get('MEDIA_URL'), } - # Override this tuple by copying to settings.py as `DEBUG_TOOLBAR_PANELS` - self.default_panels = ( - 'debug_toolbar.panels.version.VersionDebugPanel', - 'debug_toolbar.panels.timer.TimerDebugPanel', - 'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel', - 'debug_toolbar.panels.headers.HeaderDebugPanel', - 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel', - 'debug_toolbar.panels.sql.SQLDebugPanel', - 'debug_toolbar.panels.template.TemplateDebugPanel', - #'debug_toolbar.panels.cache.CacheDebugPanel', - 'debug_toolbar.panels.signals.SignalDebugPanel', - 'debug_toolbar.panels.logger.LoggingPanel', - ) + self.load_panels() self.stats = {} @@ -53,28 +41,8 @@ class DebugToolbar(object): """ Populate debug panels """ - from django.conf import settings - from django.core import exceptions - - # Check if settings has a DEBUG_TOOLBAR_PANELS, otherwise use default - if hasattr(settings, 'DEBUG_TOOLBAR_PANELS'): - self.default_panels = settings.DEBUG_TOOLBAR_PANELS - - for panel_path in self.default_panels: - try: - dot = panel_path.rindex('.') - except ValueError: - raise exceptions.ImproperlyConfigured, '%s isn\'t a debug panel module' % panel_path - panel_module, panel_classname = panel_path[:dot], panel_path[(dot + 1):] - try: - mod = __import__(panel_module, {}, {}, ['']) - except ImportError, e: - raise exceptions.ImproperlyConfigured, 'Error importing debug panel %s: "%s"' % (panel_module, e) - try: - panel_class = getattr(mod, panel_classname) - except AttributeError: - raise exceptions.ImproperlyConfigured, 'Toolbar Panel module "%s" does not define a "%s" class' % (panel_module, panel_classname) - + global panel_classes + for panel_class in panel_classes: try: panel_instance = panel_class(context=self.template_context) except: @@ -96,3 +64,44 @@ class DebugToolbar(object): }) return render_to_string('debug_toolbar/base.html', context) + + +panel_classes = [] + + +def load_panel_classes(): + from django.conf import settings + from django.core import exceptions + + # Override this tuple by copying to settings.py as `DEBUG_TOOLBAR_PANELS` + default_panels = ( + 'debug_toolbar.panels.version.VersionDebugPanel', + 'debug_toolbar.panels.timer.TimerDebugPanel', + 'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel', + 'debug_toolbar.panels.headers.HeaderDebugPanel', + 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel', + 'debug_toolbar.panels.sql.SQLDebugPanel', + 'debug_toolbar.panels.template.TemplateDebugPanel', + #'debug_toolbar.panels.cache.CacheDebugPanel', + 'debug_toolbar.panels.signals.SignalDebugPanel', + 'debug_toolbar.panels.logger.LoggingPanel', + ) + # Check if settings has a DEBUG_TOOLBAR_PANELS, otherwise use default + if hasattr(settings, 'DEBUG_TOOLBAR_PANELS'): + default_panels = settings.DEBUG_TOOLBAR_PANELS + + for panel_path in default_panels: + try: + dot = panel_path.rindex('.') + except ValueError: + raise exceptions.ImproperlyConfigured, '%s isn\'t a debug panel module' % panel_path + panel_module, panel_classname = panel_path[:dot], panel_path[dot + 1:] + try: + mod = __import__(panel_module, {}, {}, ['']) + except ImportError, e: + raise exceptions.ImproperlyConfigured, 'Error importing debug panel %s: "%s"' % (panel_module, e) + try: + panel_class = getattr(mod, panel_classname) + except AttributeError: + raise exceptions.ImproperlyConfigured, 'Toolbar Panel module "%s" does not define a "%s" class' % (panel_module, panel_classname) + panel_classes.append(panel_class) |
