diff options
| -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 | ||||
| -rw-r--r-- | docs/configuration.rst | 40 | ||||
| -rw-r--r-- | tests/__init__.py | 5 | ||||
| -rw-r--r-- | 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 = '</%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'] ] diff --git a/docs/configuration.rst b/docs/configuration.rst index 7849d2e..eebb6e9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -41,6 +41,13 @@ toolbar itself, others are specific to some panels. Toolbar options ~~~~~~~~~~~~~~~ +* ``INSERT_BEFORE`` + + Default: ``'</body>'`` + + The toolbar searches for this string in the HTML and inserts itself just + before. + * ``RENDER_PANELS`` Default: ``None`` @@ -55,13 +62,13 @@ Toolbar options right thing depending on whether the WSGI container runs multiple processes. This setting allows you to force a different behavior if needed. -* ``RESULTS_CACHE_SIZE`` +* ``RESULTS_STORE_SIZE`` Default: ``10`` The toolbar keeps up to this many results in memory. -* ``ROOT_TAG_ATTRS`` +* ``ROOT_TAG_EXTRA_ATTRS`` Default: ``''`` @@ -88,13 +95,6 @@ Toolbar options which contains your custom logic. This method should return ``True`` or ``False``. -* ``TAG`` - - Default: ``'body'`` - - If set, this will be the closing tag to which the debug toolbar will attach - itself. - Panel options ~~~~~~~~~~~~~ @@ -117,25 +117,25 @@ Panel options calls. Enabling stacktraces can increase the CPU time used when executing queries. -* ``HIDDEN_STACKTRACE_MODULES`` +* ``HIDE_DJANGO_SQL`` - Default: ``('socketserver', 'threading', 'wsgiref', 'debug_toolbar')``. The - first value is ``socketserver`` on Python 3 and ``SocketServer`` on Python - 2. + Default: ``True`` Panels: cache, SQL - Useful for eliminating server-related entries which can result - in enormous DOM structures and toolbar rendering delays. + If set to ``True`` then code in Django itself won't be shown in + stacktraces. -* ``HIDE_DJANGO_SQL`` +* ``HIDE_IN_STACKTRACES`` - Default: ``True`` + Default: ``('socketserver', 'threading', 'wsgiref', 'debug_toolbar')``. The + first value is ``socketserver`` on Python 3 and ``SocketServer`` on Python + 2. Panels: cache, SQL - If set to ``True`` then code in Django itself won't be shown in - stacktraces. + Useful for eliminating server-related entries which can result + in enormous DOM structures and toolbar rendering delays. * ``INTERCEPT_REDIRECTS`` @@ -177,5 +177,5 @@ Here's an example:: 'HIDE_DJANGO_SQL': False, 'TAG': 'div', 'ENABLE_STACKTRACES': True, - 'HIDDEN_STACKTRACE_MODULES': ('gunicorn', 'newrelic'), + 'HIDE_IN_STACKTRACES': ('gunicorn', 'newrelic'), } diff --git a/tests/__init__.py b/tests/__init__.py index 5be754e..f41162b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,11 +13,12 @@ def update_toolbar_config(**kwargs): dt_settings.CONFIG = {} dt_settings.CONFIG.update(dt_settings.CONFIG_DEFAULTS) dt_settings.CONFIG.update(kwargs['value'] or {}) - + # This doesn't account for deprecated configuration options. @receiver(setting_changed) def update_toolbar_panels(**kwargs): if kwargs['setting'] == 'DEBUG_TOOLBAR_PANELS': dt_settings.PANELS = kwargs['value'] or dt_settings.PANELS_DEFAULTS DebugToolbar._panel_classes = None - # Not implemented: invalidate debug_toolbar.urls + # Not implemented: invalidate debug_toolbar.urls. + # This doesn't account for deprecated panel names. diff --git a/tests/test_integration.py b/tests/test_integration.py index 32fd09e..f3631e4 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -135,7 +135,7 @@ class DebugToolbarLiveTestCase(LiveServerTestCase): self.assertIn("Name", table.text) self.assertIn("Version", table.text) - @override_settings(DEBUG_TOOLBAR_CONFIG={'RESULTS_CACHE_SIZE': 0}) + @override_settings(DEBUG_TOOLBAR_CONFIG={'RESULTS_STORE_SIZE': 0}) def test_expired_store(self): self.selenium.get(self.live_server_url + '/regular/basic/') version_panel = self.selenium.find_element_by_id('VersionsPanel') |
