From 1a5108a23d97f2c6d111afaff433df64c2211955 Mon Sep 17 00:00:00 2001 From: tschilling Date: Fri, 14 Feb 2014 13:56:50 -0500 Subject: Deprecating INTERCEPT_REDIRECTS in favor of DEFAULT_DISABLED_PANELS. --- debug_toolbar/panels/__init__.py | 10 +++++++++- debug_toolbar/panels/redirects.py | 5 ----- debug_toolbar/settings.py | 19 ++++++++++++++++++- docs/configuration.rst | 7 +++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py index 178ea6f..e71d7b6 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -4,6 +4,8 @@ import warnings from django.template.loader import render_to_string +from debug_toolbar import settings as dt_settings + class Panel(object): """ @@ -20,7 +22,13 @@ class Panel(object): @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 diff --git a/debug_toolbar/panels/redirects.py b/debug_toolbar/panels/redirects.py index 8bd5aba..757c65c 100644 --- a/debug_toolbar/panels/redirects.py +++ b/debug_toolbar/panels/redirects.py @@ -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") diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index 48649fd..2d02aa5 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -16,6 +16,7 @@ from django.utils import six CONFIG_DEFAULTS = { # Toolbar options + 'DEFAULT_DISABLED_PANELS': ('RedirectsPanel', ), 'INSERT_BEFORE': '', 'RENDER_PANELS': None, 'RESULTS_STORE_SIZE': 10, @@ -32,7 +33,6 @@ CONFIG_DEFAULTS = { 'debug_toolbar', 'django', ), - 'INTERCEPT_REDIRECTS': False, 'SHOW_TEMPLATE_CONTEXT': True, 'SQL_WARNING_THRESHOLD': 500, # milliseconds } @@ -125,6 +125,23 @@ else: 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') + + PATCH_SETTINGS = getattr(settings, 'DEBUG_TOOLBAR_PATCH_SETTINGS', settings.DEBUG) diff --git a/docs/configuration.rst b/docs/configuration.rst index 88226cd..4cb94f0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -57,6 +57,13 @@ toolbar itself, others are specific to some panels. Toolbar options ~~~~~~~~~~~~~~~ +* ``DEFAULT_DISABLED_PANELS`` + + Default: ``('RedirectsPanel', )`` + + A collection of panel class names that are disabled (but still displayed) + by default. + * ``INSERT_BEFORE`` Default: ``''`` -- cgit v1.2.3