Skip to content

Deprecating INTERCEPT_REDIRECTS in favor of DEFAULT_DISABLED_PANELS. #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Deprecating INTERCEPT_REDIRECTS in favor of DEFAULT_DISABLED_PANELS.
  • Loading branch information
tim-schilling committed Feb 14, 2014
commit 1a5108a23d97f2c6d111afaff433df64c2211955
10 changes: 9 additions & 1 deletion debug_toolbar/panels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from django.template.loader import render_to_string

from debug_toolbar import settings as dt_settings


class Panel(object):
"""
Expand All @@ -20,7 +22,13 @@ def panel_id(self):

@property
def enabled(self):
return self.toolbar.request.COOKIES.get('djdt' + self.panel_id, 'on') == 'on'
# Check to see if settings has a default value for it
if self.panel_id in dt_settings.CONFIG['DEFAULT_DISABLED_PANELS']:
default = 'off'
else:
default = 'on'
# The user's cookies should override the default value
return self.toolbar.request.COOKIES.get('djdt' + self.panel_id, default) == 'on'

# Titles and content

Expand Down
5 changes: 0 additions & 5 deletions debug_toolbar/panels/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class RedirectsPanel(Panel):
Panel that intercepts redirects and displays a page with debug info.
"""

@property
def enabled(self):
default = 'on' if self.toolbar.config['INTERCEPT_REDIRECTS'] else 'off'
return self.toolbar.request.COOKIES.get('djdt' + self.panel_id, default) == 'on'

has_content = False

nav_title = _("Intercept redirects")
Expand Down
19 changes: 18 additions & 1 deletion debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

CONFIG_DEFAULTS = {
# Toolbar options
'DEFAULT_DISABLED_PANELS': ('RedirectsPanel', ),
'INSERT_BEFORE': '</body>',
'RENDER_PANELS': None,
'RESULTS_STORE_SIZE': 10,
Expand All @@ -32,7 +33,6 @@
'debug_toolbar',
'django',
),
'INTERCEPT_REDIRECTS': False,
'SHOW_TEMPLATE_CONTEXT': True,
'SQL_WARNING_THRESHOLD': 500, # milliseconds
}
Expand Down Expand Up @@ -125,6 +125,23 @@
PANELS[index] = new_panel


if 'INTERCEPT_REDIRECTS' in USER_CONFIG:
warnings.warn(
"INTERCEPT_REDIRECTS is deprecated. Please use the "
"DEFAULT_DISABLED_PANELS config in the"
"DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning)
if USER_CONFIG['INTERCEPT_REDIRECTS']:
if 'RedirectsPanel' in CONFIG['DEFAULT_DISABLED_PANELS']:
# RedirectsPanel should be enabled
CONFIG['DEFAULT_DISABLED_PANELS'] = [
panel for panel in CONFIG['DEFAULT_DISABLED_PANELS']
if panel != "RedirectsPanel"
]
elif not 'RedirectsPanel' in CONFIG['DEFAULT_DISABLED_PANELS']:
# RedirectsPanel should be disabled
CONFIG['DEFAULT_DISABLED_PANELS'].append('RedirectsPanel')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value, which is documented, is a tuple. And you cannot append to tuples.

Since all we're doing is testing for inclusion, you could cast DEFAULT_DISABLED_PANELS = set(DEFAULT_DISABLED_PANELS), which would make it easier to add or remove items with simple set operations (add / delete if I remember correctly).



PATCH_SETTINGS = getattr(settings, 'DEBUG_TOOLBAR_PATCH_SETTINGS', settings.DEBUG)


Expand Down
7 changes: 7 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ toolbar itself, others are specific to some panels.
Toolbar options
~~~~~~~~~~~~~~~

* ``DEFAULT_DISABLED_PANELS``

Default: ``('RedirectsPanel', )``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use fully-qualified identifiers as in DEBUG_TOOLBAR_PANELS?

It's technically possible to have two panels with the same class name in different modules. That doesn't happen with built-in panels, but it could happen with external panels.


A collection of panel class names that are disabled (but still displayed)
by default.

* ``INSERT_BEFORE``

Default: ``'</body>'``
Expand Down