Skip to content

Commit 908b49c

Browse files
committed
Rename some settings for clarity and consistency.
Thanks Jannis for his help.
1 parent e7692b3 commit 908b49c

File tree

8 files changed

+62
-46
lines changed

8 files changed

+62
-46
lines changed

debug_toolbar/middleware.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ class DebugToolbarMiddleware(object):
5252
debug_toolbars = {}
5353

5454
def __init__(self):
55-
# The method to call to decide to show the toolbar
5655
self.show_toolbar = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK'] or show_toolbar
57-
58-
# The tag to attach the toolbar to
59-
self.tag = '</%s>' % dt_settings.CONFIG['TAG']
56+
self.insert_before = dt_settings.CONFIG['INSERT_BEFORE']
6057

6158
def process_request(self, request):
6259
if not self.show_toolbar(request):
@@ -99,8 +96,8 @@ def process_response(self, request, response):
9996
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES):
10097
response.content = replace_insensitive(
10198
force_text(response.content, encoding=settings.DEFAULT_CHARSET),
102-
self.tag,
103-
force_text(toolbar.render_toolbar() + self.tag))
99+
self.insert_before,
100+
force_text(toolbar.render_toolbar() + self.insert_before))
104101
if response.get('Content-Length', None):
105102
response['Content-Length'] = len(response.content)
106103
return response

debug_toolbar/settings.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,48 @@
1414

1515

1616
CONFIG_DEFAULTS = {
17-
'INTERCEPT_REDIRECTS': False,
17+
# Toolbar options
18+
'INSERT_BEFORE': '</body>',
19+
'RENDER_PANELS': None,
20+
'RESULTS_STORE_SIZE': 10,
21+
'ROOT_TAG_EXTRA_ATTRS': '',
22+
'SHOW_COLLAPSED': False,
1823
'SHOW_TOOLBAR_CALLBACK': None,
24+
# Panel options
1925
'EXTRA_SIGNALS': [],
20-
'SHOW_COLLAPSED': False,
21-
'HIDE_DJANGO_SQL': True,
22-
'SHOW_TEMPLATE_CONTEXT': True,
23-
'TAG': 'body',
2426
'ENABLE_STACKTRACES': True,
25-
'HIDDEN_STACKTRACE_MODULES': (
27+
'HIDE_DJANGO_SQL': True,
28+
'HIDE_IN_STACKTRACES': (
2629
'socketserver' if six.PY3 else 'SocketServer',
2730
'threading',
2831
'wsgiref',
2932
'debug_toolbar',
3033
),
31-
'ROOT_TAG_ATTRS': '',
34+
'INTERCEPT_REDIRECTS': False,
35+
'SHOW_TEMPLATE_CONTEXT': True,
3236
'SQL_WARNING_THRESHOLD': 500, # milliseconds
33-
'RESULTS_CACHE_SIZE': 10,
34-
'RENDER_PANELS': None,
3537
}
3638

37-
38-
CONFIG = {}
39-
CONFIG.update(CONFIG_DEFAULTS)
40-
CONFIG.update(getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}))
39+
CONFIG = CONFIG_DEFAULTS.copy()
40+
USER_CONFIG = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
41+
# Backward-compatibility for 1.0, remove in 2.0.
42+
_RENAMED_CONFIG = {
43+
'RESULTS_STORE_SIZE': 'RESULTS_CACHE_SIZE',
44+
'ROOT_TAG_ATTRS': 'ROOT_TAG_EXTRA_ATTRS',
45+
'HIDDEN_STACKTRACE_MODULES': 'HIDE_IN_STACKTRACES'
46+
}
47+
for old_name, new_name in _RENAMED_CONFIG.items():
48+
if old_name in USER_CONFIG:
49+
warnings.warn(
50+
"%r was renamed to %r. Update your DEBUG_TOOLBAR_CONFIG "
51+
"setting." % (old_name, new_name), DeprecationWarning)
52+
USER_CONFIG[new_name] = USER_CONFIG.pop(old_name)
53+
if 'TAG' in USER_CONFIG:
54+
warnings.warn(
55+
"TAG was replaced by INSERT_BEFORE. Update your "
56+
"DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning)
57+
USER_CONFIG['INSERT_BEFORE'] = '</%s>' % USER_CONFIG.pop('TAG')
58+
CONFIG.update(USER_CONFIG)
4159

4260

4361
PANELS_DEFAULTS = [

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script src="{{ STATIC_URL }}debug_toolbar/js/toolbar.js"></script>
1111
<div id="djDebug" style="display:none;" dir="ltr"
1212
data-store-id="{{ toolbar.store_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"
13-
{{ toolbar.config.ROOT_TAG_ATTRS|safe }}>
13+
{{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }}>
1414
<div style="display:none;" id="djDebugToolbar">
1515
<ul id="djDebugPanelList">
1616
{% if toolbar.panels %}

debug_toolbar/toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def store(self):
7979
self.store_id = uuid.uuid4().hex
8080
cls = type(self)
8181
cls._store[self.store_id] = self
82-
for _ in range(len(cls._store) - self.config['RESULTS_CACHE_SIZE']):
82+
for _ in range(len(cls._store) - self.config['RESULTS_STORE_SIZE']):
8383
# When we drop support for Python 2.6 and switch to
8484
# collections.OrderedDict, use popitem(last=False).
8585
del cls._store[cls._store.keyOrder[0]]

debug_toolbar/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_module_path(module_name):
2525
module = import_module(module_name)
2626
except ImportError as e:
2727
raise ImproperlyConfigured(
28-
'Error importing HIDDEN_STACKTRACE_MODULES: %s' % (e,))
28+
'Error importing HIDE_IN_STACKTRACES: %s' % (e,))
2929
else:
3030
source_path = inspect.getsourcefile(module)
3131
if source_path.endswith('__init__.py'):
@@ -35,7 +35,7 @@ def get_module_path(module_name):
3535

3636
hidden_paths = [
3737
get_module_path(module_name)
38-
for module_name in CONFIG['HIDDEN_STACKTRACE_MODULES']
38+
for module_name in CONFIG['HIDE_IN_STACKTRACES']
3939
]
4040

4141

docs/configuration.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ toolbar itself, others are specific to some panels.
4141
Toolbar options
4242
~~~~~~~~~~~~~~~
4343

44+
* ``INSERT_BEFORE``
45+
46+
Default: ``'</body>'``
47+
48+
The toolbar searches for this string in the HTML and inserts itself just
49+
before.
50+
4451
* ``RENDER_PANELS``
4552

4653
Default: ``None``
@@ -55,13 +62,13 @@ Toolbar options
5562
right thing depending on whether the WSGI container runs multiple processes.
5663
This setting allows you to force a different behavior if needed.
5764

58-
* ``RESULTS_CACHE_SIZE``
65+
* ``RESULTS_STORE_SIZE``
5966

6067
Default: ``10``
6168

6269
The toolbar keeps up to this many results in memory.
6370

64-
* ``ROOT_TAG_ATTRS``
71+
* ``ROOT_TAG_EXTRA_ATTRS``
6572

6673
Default: ``''``
6774

@@ -88,13 +95,6 @@ Toolbar options
8895
which contains your custom logic. This method should return ``True`` or
8996
``False``.
9097

91-
* ``TAG``
92-
93-
Default: ``'body'``
94-
95-
If set, this will be the closing tag to which the debug toolbar will attach
96-
itself.
97-
9898
Panel options
9999
~~~~~~~~~~~~~
100100

@@ -117,25 +117,25 @@ Panel options
117117
calls. Enabling stacktraces can increase the CPU time used when executing
118118
queries.
119119

120-
* ``HIDDEN_STACKTRACE_MODULES``
120+
* ``HIDE_DJANGO_SQL``
121121

122-
Default: ``('socketserver', 'threading', 'wsgiref', 'debug_toolbar')``. The
123-
first value is ``socketserver`` on Python 3 and ``SocketServer`` on Python
124-
2.
122+
Default: ``True``
125123

126124
Panels: cache, SQL
127125

128-
Useful for eliminating server-related entries which can result
129-
in enormous DOM structures and toolbar rendering delays.
126+
If set to ``True`` then code in Django itself won't be shown in
127+
stacktraces.
130128

131-
* ``HIDE_DJANGO_SQL``
129+
* ``HIDE_IN_STACKTRACES``
132130

133-
Default: ``True``
131+
Default: ``('socketserver', 'threading', 'wsgiref', 'debug_toolbar')``. The
132+
first value is ``socketserver`` on Python 3 and ``SocketServer`` on Python
133+
2.
134134

135135
Panels: cache, SQL
136136

137-
If set to ``True`` then code in Django itself won't be shown in
138-
stacktraces.
137+
Useful for eliminating server-related entries which can result
138+
in enormous DOM structures and toolbar rendering delays.
139139

140140
* ``INTERCEPT_REDIRECTS``
141141

@@ -177,5 +177,5 @@ Here's an example::
177177
'HIDE_DJANGO_SQL': False,
178178
'TAG': 'div',
179179
'ENABLE_STACKTRACES': True,
180-
'HIDDEN_STACKTRACE_MODULES': ('gunicorn', 'newrelic'),
180+
'HIDE_IN_STACKTRACES': ('gunicorn', 'newrelic'),
181181
}

tests/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def update_toolbar_config(**kwargs):
1313
dt_settings.CONFIG = {}
1414
dt_settings.CONFIG.update(dt_settings.CONFIG_DEFAULTS)
1515
dt_settings.CONFIG.update(kwargs['value'] or {})
16-
16+
# This doesn't account for deprecated configuration options.
1717

1818
@receiver(setting_changed)
1919
def update_toolbar_panels(**kwargs):
2020
if kwargs['setting'] == 'DEBUG_TOOLBAR_PANELS':
2121
dt_settings.PANELS = kwargs['value'] or dt_settings.PANELS_DEFAULTS
2222
DebugToolbar._panel_classes = None
23-
# Not implemented: invalidate debug_toolbar.urls
23+
# Not implemented: invalidate debug_toolbar.urls.
24+
# This doesn't account for deprecated panel names.

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_basic(self):
135135
self.assertIn("Name", table.text)
136136
self.assertIn("Version", table.text)
137137

138-
@override_settings(DEBUG_TOOLBAR_CONFIG={'RESULTS_CACHE_SIZE': 0})
138+
@override_settings(DEBUG_TOOLBAR_CONFIG={'RESULTS_STORE_SIZE': 0})
139139
def test_expired_store(self):
140140
self.selenium.get(self.live_server_url + '/regular/basic/')
141141
version_panel = self.selenium.find_element_by_id('VersionsPanel')

0 commit comments

Comments
 (0)