aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/utils
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-12 22:05:52 +0100
committerAymeric Augustin2013-11-12 22:15:50 +0100
commitf48039e3bad9e24a59a25ed5636b428e11784da9 (patch)
treedbb6471cbf1ceb504d9932639b3ca40a57b89a31 /debug_toolbar/utils
parentc1d50fc79645c71987ae156d371777dd371c422d (diff)
downloaddjango-debug-toolbar-f48039e3bad9e24a59a25ed5636b428e11784da9.tar.bz2
Move the logic to load panels inside the DebugToolbar class.
This has the additional advantage of eliminating a side-effect that happened at import time unnecessarily. It justified refactoring the way we handle settings and defaults.
Diffstat (limited to 'debug_toolbar/utils')
-rw-r--r--debug_toolbar/utils/settings.py24
-rw-r--r--debug_toolbar/utils/tracking/db.py6
2 files changed, 27 insertions, 3 deletions
diff --git a/debug_toolbar/utils/settings.py b/debug_toolbar/utils/settings.py
index 12dc231..45f661f 100644
--- a/debug_toolbar/utils/settings.py
+++ b/debug_toolbar/utils/settings.py
@@ -4,6 +4,13 @@ from django.conf import settings
from django.utils import six
+# Always import this module as follows:
+# from debug_toolbar.utils import settings [as dt_settings]
+
+# Don't import directly CONFIG or PANELs, or you will miss changes performed
+# with override_settings in tests.
+
+
CONFIG_DEFAULTS = {
'INTERCEPT_REDIRECTS': False,
'SHOW_TOOLBAR_CALLBACK': None,
@@ -27,3 +34,20 @@ CONFIG_DEFAULTS = {
CONFIG = {}
CONFIG.update(CONFIG_DEFAULTS)
CONFIG.update(getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}))
+
+
+PANELS_DEFAULTS = (
+ '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',
+)
+
+
+PANELS = getattr(settings, 'DEBUG_TOOLBAR_PANELS', PANELS_DEFAULTS)
diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py
index 157334a..fd56ff9 100644
--- a/debug_toolbar/utils/tracking/db.py
+++ b/debug_toolbar/utils/tracking/db.py
@@ -11,7 +11,7 @@ from django.utils.encoding import force_text
from django.utils import six
from debug_toolbar.utils import tidy_stacktrace, get_template_info, get_stack
-from debug_toolbar.utils.settings import CONFIG
+from debug_toolbar.utils import settings as dt_settings
class SQLQueryTriggered(Exception):
@@ -92,7 +92,7 @@ class NormalCursorWrapper(object):
finally:
stop_time = time()
duration = (stop_time - start_time) * 1000
- if CONFIG['ENABLE_STACKTRACES']:
+ if dt_settings.CONFIG['ENABLE_STACKTRACES']:
stacktrace = tidy_stacktrace(reversed(get_stack()))
else:
stacktrace = []
@@ -135,7 +135,7 @@ class NormalCursorWrapper(object):
'stacktrace': stacktrace,
'start_time': start_time,
'stop_time': stop_time,
- 'is_slow': duration > CONFIG['SQL_WARNING_THRESHOLD'],
+ 'is_slow': duration > dt_settings.CONFIG['SQL_WARNING_THRESHOLD'],
'is_select': sql.lower().strip().startswith('select'),
'template_info': template_info,
}