From 908b49cb7d2d527b701996f0d0b9e1e19e765819 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 24 Nov 2013 11:26:07 +0100 Subject: Rename some settings for clarity and consistency. Thanks Jannis for his help. --- debug_toolbar/middleware.py | 9 ++--- debug_toolbar/settings.py | 44 +++++++++++++++++-------- debug_toolbar/templates/debug_toolbar/base.html | 2 +- debug_toolbar/toolbar.py | 2 +- debug_toolbar/utils.py | 4 +-- docs/configuration.rst | 40 +++++++++++----------- tests/__init__.py | 5 +-- tests/test_integration.py | 2 +- 8 files changed, 62 insertions(+), 46 deletions(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 3c9edf0..cd64c60 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -52,11 +52,8 @@ class DebugToolbarMiddleware(object): debug_toolbars = {} def __init__(self): - # The method to call to decide to show the toolbar self.show_toolbar = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK'] or show_toolbar - - # The tag to attach the toolbar to - self.tag = '' % dt_settings.CONFIG['TAG'] + self.insert_before = dt_settings.CONFIG['INSERT_BEFORE'] def process_request(self, request): if not self.show_toolbar(request): @@ -99,8 +96,8 @@ class DebugToolbarMiddleware(object): response.get('Content-Type', '').split(';')[0] in _HTML_TYPES): response.content = replace_insensitive( force_text(response.content, encoding=settings.DEFAULT_CHARSET), - self.tag, - force_text(toolbar.render_toolbar() + self.tag)) + self.insert_before, + force_text(toolbar.render_toolbar() + self.insert_before)) if response.get('Content-Length', None): response['Content-Length'] = len(response.content) return response diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index 7e23122..6d21c34 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -14,30 +14,48 @@ from django.utils import six CONFIG_DEFAULTS = { - 'INTERCEPT_REDIRECTS': False, + # Toolbar options + 'INSERT_BEFORE': '', + 'RENDER_PANELS': None, + 'RESULTS_STORE_SIZE': 10, + 'ROOT_TAG_EXTRA_ATTRS': '', + 'SHOW_COLLAPSED': False, 'SHOW_TOOLBAR_CALLBACK': None, + # Panel options 'EXTRA_SIGNALS': [], - 'SHOW_COLLAPSED': False, - 'HIDE_DJANGO_SQL': True, - 'SHOW_TEMPLATE_CONTEXT': True, - 'TAG': 'body', 'ENABLE_STACKTRACES': True, - 'HIDDEN_STACKTRACE_MODULES': ( + 'HIDE_DJANGO_SQL': True, + 'HIDE_IN_STACKTRACES': ( 'socketserver' if six.PY3 else 'SocketServer', 'threading', 'wsgiref', 'debug_toolbar', ), - 'ROOT_TAG_ATTRS': '', + 'INTERCEPT_REDIRECTS': False, + 'SHOW_TEMPLATE_CONTEXT': True, 'SQL_WARNING_THRESHOLD': 500, # milliseconds - 'RESULTS_CACHE_SIZE': 10, - 'RENDER_PANELS': None, } - -CONFIG = {} -CONFIG.update(CONFIG_DEFAULTS) -CONFIG.update(getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})) +CONFIG = CONFIG_DEFAULTS.copy() +USER_CONFIG = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) +# Backward-compatibility for 1.0, remove in 2.0. +_RENAMED_CONFIG = { + 'RESULTS_STORE_SIZE': 'RESULTS_CACHE_SIZE', + 'ROOT_TAG_ATTRS': 'ROOT_TAG_EXTRA_ATTRS', + 'HIDDEN_STACKTRACE_MODULES': 'HIDE_IN_STACKTRACES' +} +for old_name, new_name in _RENAMED_CONFIG.items(): + if old_name in USER_CONFIG: + warnings.warn( + "%r was renamed to %r. Update your DEBUG_TOOLBAR_CONFIG " + "setting." % (old_name, new_name), DeprecationWarning) + USER_CONFIG[new_name] = USER_CONFIG.pop(old_name) +if 'TAG' in USER_CONFIG: + warnings.warn( + "TAG was replaced by INSERT_BEFORE. Update your " + "DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning) + USER_CONFIG['INSERT_BEFORE'] = '' % USER_CONFIG.pop('TAG') +CONFIG.update(USER_CONFIG) PANELS_DEFAULTS = [ diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index 119e713..8a5e070 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -10,7 +10,7 @@ if(!window.jQuery) document.write('