aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debug_toolbar/panels/__init__.py35
-rw-r--r--debug_toolbar/toolbar/loader.py19
2 files changed, 32 insertions, 22 deletions
diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py
index fa2e4b6..584ddb7 100644
--- a/debug_toolbar/panels/__init__.py
+++ b/debug_toolbar/panels/__init__.py
@@ -1,4 +1,6 @@
-"""Base DebugPanel class"""
+from django.template.defaultfilters import slugify
+from debug_toolbar.middleware import DebugToolbarMiddleware
+
class DebugPanel(object):
"""
@@ -6,43 +8,50 @@ class DebugPanel(object):
"""
# name = Base
has_content = False # If content returns something, set to true in subclass
-
+
# We'll maintain a local context instance so we can expose our template
# context variables to panels which need them:
context = {}
-
+
# Panel methods
def __init__(self, context={}):
self.context.update(context)
-
+ self.toolbar = DebugToolbarMiddleware.get_current()
+ self.slug = slugify(self.name)
+
def dom_id(self):
return 'djDebug%sPanel' % (self.name.replace(' ', ''))
-
+
def nav_title(self):
"""Title showing in toolbar"""
raise NotImplementedError
-
+
def nav_subtitle(self):
"""Subtitle showing until title in toolbar"""
return ''
-
+
def title(self):
"""Title showing in panel"""
raise NotImplementedError
-
+
def url(self):
raise NotImplementedError
-
+
def content(self):
raise NotImplementedError
-
+
+ def record_stats(self, stats):
+ self.toolbar.stats[self.slug].update(stats)
+
+ def get_stats(self):
+ return self.toolbar.stats[self.slug]
+
# Standard middleware methods
def process_request(self, request):
pass
-
+
def process_view(self, request, view_func, view_args, view_kwargs):
pass
-
+
def process_response(self, request, response):
pass
-
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py
index 3501c69..cf7a243 100644
--- a/debug_toolbar/toolbar/loader.py
+++ b/debug_toolbar/toolbar/loader.py
@@ -9,7 +9,7 @@ from django.utils.datastructures import SortedDict
from django.utils.safestring import mark_safe
class DebugToolbar(object):
-
+
def __init__(self, request):
self.request = request
self._panels = SortedDict()
@@ -38,25 +38,26 @@ class DebugToolbar(object):
'debug_toolbar.panels.logger.LoggingPanel',
)
self.load_panels()
+ self.stats = {}
def _get_panels(self):
return self._panels.values()
panels = property(_get_panels)
-
+
def get_panel(self, cls):
return self._panels[cls]
-
+
def load_panels(self):
"""
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('.')
@@ -71,14 +72,14 @@ class DebugToolbar(object):
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)
-
+
try:
panel_instance = panel_class(context=self.template_context)
except:
raise # Bubble up problem loading panel
-
+
self._panels[panel_class] = panel_instance
-
+
def render_toolbar(self):
"""
Renders the overall Toolbar with panels inside.
@@ -91,5 +92,5 @@ class DebugToolbar(object):
'js': mark_safe(open(os.path.join(media_path, 'js', 'toolbar.min.js'), 'r').read()),
'css': mark_safe(open(os.path.join(media_path, 'css', 'toolbar.min.css'), 'r').read()),
})
-
+
return render_to_string('debug_toolbar/base.html', context)