From 1a5108a23d97f2c6d111afaff433df64c2211955 Mon Sep 17 00:00:00 2001 From: tschilling Date: Fri, 14 Feb 2014 13:56:50 -0500 Subject: [PATCH 1/3] 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 178ea6f2d..e71d7b6b7 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -4,6 +4,8 @@ from django.template.loader import render_to_string +from debug_toolbar import settings as dt_settings + class Panel(object): """ @@ -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 diff --git a/debug_toolbar/panels/redirects.py b/debug_toolbar/panels/redirects.py index 8bd5aba0b..757c65cbe 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 48649fdad..2d02aa5f0 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -16,6 +16,7 @@ CONFIG_DEFAULTS = { # Toolbar options + 'DEFAULT_DISABLED_PANELS': ('RedirectsPanel', ), 'INSERT_BEFORE': '', 'RENDER_PANELS': None, 'RESULTS_STORE_SIZE': 10, @@ -32,7 +33,6 @@ 'debug_toolbar', 'django', ), - 'INTERCEPT_REDIRECTS': False, 'SHOW_TEMPLATE_CONTEXT': True, 'SQL_WARNING_THRESHOLD': 500, # milliseconds } @@ -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') + + PATCH_SETTINGS = getattr(settings, 'DEBUG_TOOLBAR_PATCH_SETTINGS', settings.DEBUG) diff --git a/docs/configuration.rst b/docs/configuration.rst index 88226cd2f..4cb94f0d0 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: ``''`` From cc08c0d19bd5d1c7ff2281e3c3e4d92fa932e6d5 Mon Sep 17 00:00:00 2001 From: tschilling Date: Sat, 15 Feb 2014 08:59:20 -0500 Subject: [PATCH 2/3] Changing the collection to be fully qualified names and for it to be a set not a tuple. --- debug_toolbar/panels/__init__.py | 3 ++- debug_toolbar/settings.py | 23 +++++++++++++++-------- docs/configuration.rst | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py index e71d7b6b7..a7e352891 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -5,6 +5,7 @@ from django.template.loader import render_to_string from debug_toolbar import settings as dt_settings +from debug_toolbar.utils import get_name_from_obj class Panel(object): @@ -23,7 +24,7 @@ def panel_id(self): @property def enabled(self): # Check to see if settings has a default value for it - if self.panel_id in dt_settings.CONFIG['DEFAULT_DISABLED_PANELS']: + if get_name_from_obj(self) in dt_settings.CONFIG['DEFAULT_DISABLED_PANELS']: default = 'off' else: default = 'on' diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index 2d02aa5f0..0ea75abe8 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -16,7 +16,7 @@ CONFIG_DEFAULTS = { # Toolbar options - 'DEFAULT_DISABLED_PANELS': ('RedirectsPanel', ), + 'DEFAULT_DISABLED_PANELS': {'debug_toolbar.panels.redirects.RedirectsPanel'}, 'INSERT_BEFORE': '', 'RENDER_PANELS': None, 'RESULTS_STORE_SIZE': 10, @@ -131,15 +131,22 @@ "DEFAULT_DISABLED_PANELS config in the" "DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning) if USER_CONFIG['INTERCEPT_REDIRECTS']: - if 'RedirectsPanel' in CONFIG['DEFAULT_DISABLED_PANELS']: + if 'debug_toolbar.panels.redirects.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']: + try: + CONFIG['DEFAULT_DISABLED_PANELS'].remove( + 'debug_toolbar.panels.redirects.RedirectsPanel' + ) + except KeyError: + # We wanted to remove it, but it didn't exist. This is fine + pass + elif not 'debug_toolbar.panels.redirects.RedirectsPanel' \ + in CONFIG['DEFAULT_DISABLED_PANELS']: # RedirectsPanel should be disabled - CONFIG['DEFAULT_DISABLED_PANELS'].append('RedirectsPanel') + CONFIG['DEFAULT_DISABLED_PANELS'].add( + 'debug_toolbar.panels.redirects.RedirectsPanel' + ) PATCH_SETTINGS = getattr(settings, 'DEBUG_TOOLBAR_PATCH_SETTINGS', settings.DEBUG) diff --git a/docs/configuration.rst b/docs/configuration.rst index 4cb94f0d0..972d9ac6c 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -59,10 +59,10 @@ Toolbar options * ``DEFAULT_DISABLED_PANELS`` - Default: ``('RedirectsPanel', )`` + Default: ``{'debug_toolbar.panels.redirects.RedirectsPanel'}`` - A collection of panel class names that are disabled (but still displayed) - by default. + This setting is a set of the full Python paths to each panel that you + want disabled (but still displayed) by default. * ``INSERT_BEFORE`` From 5fd65ef273ff011c156b8a6953b667f8b6b6c249 Mon Sep 17 00:00:00 2001 From: tschilling Date: Sat, 15 Feb 2014 09:07:31 -0500 Subject: [PATCH 3/3] Changing set declaration. --- debug_toolbar/settings.py | 2 +- docs/configuration.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index 0ea75abe8..2c718886e 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -16,7 +16,7 @@ CONFIG_DEFAULTS = { # Toolbar options - 'DEFAULT_DISABLED_PANELS': {'debug_toolbar.panels.redirects.RedirectsPanel'}, + 'DEFAULT_DISABLED_PANELS': set(['debug_toolbar.panels.redirects.RedirectsPanel']), 'INSERT_BEFORE': '', 'RENDER_PANELS': None, 'RESULTS_STORE_SIZE': 10, diff --git a/docs/configuration.rst b/docs/configuration.rst index 972d9ac6c..8ad9087d9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -59,7 +59,7 @@ Toolbar options * ``DEFAULT_DISABLED_PANELS`` - Default: ``{'debug_toolbar.panels.redirects.RedirectsPanel'}`` + Default: ``set(['debug_toolbar.panels.redirects.RedirectsPanel'])`` This setting is a set of the full Python paths to each panel that you want disabled (but still displayed) by default.