diff options
| author | Aymeric Augustin | 2013-11-24 11:26:07 +0100 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-24 11:26:07 +0100 |
| commit | 908b49cb7d2d527b701996f0d0b9e1e19e765819 (patch) | |
| tree | 545635570f264761d7314aa761cd36d1e6a56f7c /debug_toolbar | |
| parent | e7692b33ca7fd3f7704d283d6b1368cdea198d59 (diff) | |
| download | django-debug-toolbar-908b49cb7d2d527b701996f0d0b9e1e19e765819.tar.bz2 | |
Rename some settings for clarity and consistency.
Thanks Jannis for his help.
Diffstat (limited to 'debug_toolbar')
| -rw-r--r-- | debug_toolbar/middleware.py | 9 | ||||
| -rw-r--r-- | debug_toolbar/settings.py | 44 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/base.html | 2 | ||||
| -rw-r--r-- | debug_toolbar/toolbar.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/utils.py | 4 |
5 files changed, 38 insertions, 23 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 = '</%s>' % 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': '</body>', + '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'] = '</%s>' % 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('<scr'+'ipt src="//ajax.googleapis.com/ajax/li <script src="{{ STATIC_URL }}debug_toolbar/js/toolbar.js"></script> <div id="djDebug" style="display:none;" dir="ltr" data-store-id="{{ toolbar.store_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}" - {{ toolbar.config.ROOT_TAG_ATTRS|safe }}> + {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }}> <div style="display:none;" id="djDebugToolbar"> <ul id="djDebugPanelList"> {% if toolbar.panels %} diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index 57ded5b..de9d69d 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -79,7 +79,7 @@ class DebugToolbar(object): self.store_id = uuid.uuid4().hex cls = type(self) cls._store[self.store_id] = self - for _ in range(len(cls._store) - self.config['RESULTS_CACHE_SIZE']): + for _ in range(len(cls._store) - self.config['RESULTS_STORE_SIZE']): # When we drop support for Python 2.6 and switch to # collections.OrderedDict, use popitem(last=False). del cls._store[cls._store.keyOrder[0]] diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index 811f1b2..065c810 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -25,7 +25,7 @@ def get_module_path(module_name): module = import_module(module_name) except ImportError as e: raise ImproperlyConfigured( - 'Error importing HIDDEN_STACKTRACE_MODULES: %s' % (e,)) + 'Error importing HIDE_IN_STACKTRACES: %s' % (e,)) else: source_path = inspect.getsourcefile(module) if source_path.endswith('__init__.py'): @@ -35,7 +35,7 @@ def get_module_path(module_name): hidden_paths = [ get_module_path(module_name) - for module_name in CONFIG['HIDDEN_STACKTRACE_MODULES'] + for module_name in CONFIG['HIDE_IN_STACKTRACES'] ] |
