diff options
| author | Aymeric Augustin | 2013-10-27 12:48:44 +0100 |
|---|---|---|
| committer | Aymeric Augustin | 2013-10-27 12:48:44 +0100 |
| commit | 9cb9796791062c9d208c0f887dc65142d42c022a (patch) | |
| tree | 40ba69bec7f39115ccfcc88c5b1cfa2baf2f86ea /debug_toolbar/utils | |
| parent | c710140a15222af2cf31b7579c6a5fedf9a482d5 (diff) | |
| download | django-debug-toolbar-9cb9796791062c9d208c0f887dc65142d42c022a.tar.bz2 | |
Centralize access to config and default values.
Diffstat (limited to 'debug_toolbar/utils')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 15 | ||||
| -rw-r--r-- | debug_toolbar/utils/settings.py | 27 | ||||
| -rw-r--r-- | debug_toolbar/utils/tracking/db.py | 13 |
3 files changed, 33 insertions, 22 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index 73e38e2..c421dce 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -14,13 +14,11 @@ from django.utils.safestring import mark_safe from django.utils import six from django.views.debug import linebreak_iter +from .settings import CONFIG # Figure out some paths django_path = os.path.realpath(os.path.dirname(django.__file__)) -config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) -hide_django_sql = config.get('HIDE_DJANGO_SQL', True) - def get_module_path(module_name): try: @@ -37,14 +35,7 @@ def get_module_path(module_name): hidden_paths = [ get_module_path(module_name) - for module_name in config.get( - 'HIDDEN_STACKTRACE_MODULES', ( - 'socketserver' if six.PY3 else 'SocketServer', - 'threading', - 'wsgiref', - 'debug_toolbar', - ) - ) + for module_name in CONFIG['HIDDEN_STACKTRACE_MODULES'] ] @@ -68,7 +59,7 @@ def tidy_stacktrace(stack): # inspection. if '__traceback_hide__' in frame.f_locals: continue - if hide_django_sql and django_path in s_path and not 'django/contrib' in s_path: + if CONFIG['HIDE_DJANGO_SQL'] and django_path in s_path and not 'django/contrib' in s_path: continue if omit_path(s_path): continue diff --git a/debug_toolbar/utils/settings.py b/debug_toolbar/utils/settings.py new file mode 100644 index 0000000..482781b --- /dev/null +++ b/debug_toolbar/utils/settings.py @@ -0,0 +1,27 @@ +from __future__ import unicode_literals + +from django.conf import settings +from django.utils import six + + +CONFIG_DEFAULTS = { + 'INTERCEPT_REDIRECTS': False, + 'SHOW_TOOLBAR_CALLBACK': None, + 'EXTRA_SIGNALS': [], + 'HIDE_DJANGO_SQL': True, + 'SHOW_TEMPLATE_CONTEXT': True, + 'TAG': 'body', + 'ENABLE_STACKTRACES': True, + 'HIDDEN_STACKTRACE_MODULES': ( + 'socketserver' if six.PY3 else 'SocketServer', + 'threading', + 'wsgiref', + 'debug_toolbar', + ), + 'ROOT_TAG_ATTRS': '', +} + + +CONFIG = {} +CONFIG.update(CONFIG_DEFAULTS) +CONFIG.update(getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})) diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py index 5822270..b195f4a 100644 --- a/debug_toolbar/utils/tracking/db.py +++ b/debug_toolbar/utils/tracking/db.py @@ -12,12 +12,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 - - -# TODO:This should be set in the toolbar loader as a default and panels should -# get a copy of the toolbar object with access to its config dictionary -DEBUG_TOOLBAR_CONFIG = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) -SQL_WARNING_THRESHOLD = DEBUG_TOOLBAR_CONFIG.get('SQL_WARNING_THRESHOLD', 500) +from debug_toolbar.utils.settings import CONFIG class SQLQueryTriggered(Exception): @@ -98,9 +93,7 @@ class NormalCursorWrapper(object): finally: stop_time = time() duration = (stop_time - start_time) * 1000 - debug_toolbar_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) - enable_stacktraces = debug_toolbar_config.get('ENABLE_STACKTRACES', True) - if enable_stacktraces: + if CONFIG['ENABLE_STACKTRACES']: stacktrace = tidy_stacktrace(reversed(get_stack())) else: stacktrace = [] @@ -143,7 +136,7 @@ class NormalCursorWrapper(object): 'stacktrace': stacktrace, 'start_time': start_time, 'stop_time': stop_time, - 'is_slow': (duration > SQL_WARNING_THRESHOLD), + 'is_slow': (duration > CONFIG.get('SQL_WARNING_THRESHOLD', 500)), 'is_select': sql.lower().strip().startswith('select'), 'template_info': template_info, } |
