Skip to content

Commit

Permalink
Support disabling panels with the names in the docs.
Browse files Browse the repository at this point in the history
The docs hide the fact that the SQLPanel and TemplatesPanel live in
a panel module. The DISABLE_PANELS config option previously required
that panel module to be included in the path in order for the panel
to be disabled.

This change will check the panel's path against that config set and
then check it again with the .panel. replaced as just . against the
config set.

Doing this replace blindly will support moving any other panel from
it's own module into a package like the SQLPanel and TemplatesPanel.

Fixes #687.
  • Loading branch information
tim-schilling committed Apr 27, 2015
1 parent 136eb4a commit 30e56bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion debug_toolbar/panels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ def panel_id(self):
@property
def enabled(self):
# Check to see if settings has a default value for it
if get_name_from_obj(self) in dt_settings.CONFIG['DISABLE_PANELS']:
disabled_panels = dt_settings.CONFIG['DISABLE_PANELS']
panel_path = get_name_from_obj(self)
# Some panels such as the SQLPanel and TemplatesPanel exist in a
# panel module, but can be disabled without panel in the path.
# For that reason, replace .panel. in the path and check for that
# value in the disabled panels as well.
disable_panel = (
panel_path in disabled_panels or
panel_path.replace('.panel.', '.') in disabled_panels)
if disable_panel:
default = 'off'
else:
default = 'on'
Expand Down
8 changes: 8 additions & 0 deletions tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def tearDown(self):
self.panel.disable_instrumentation()
super(SQLPanelTestCase, self).tearDown()

def test_disabled(self):
config = {
'DISABLE_PANELS': set(['debug_toolbar.panels.sql.SQLPanel'])
}
self.assertTrue(self.panel.enabled)
with self.settings(DEBUG_TOOLBAR_CONFIG=config):
self.assertFalse(self.panel.enabled)

def test_recording(self):
self.assertEqual(len(self.panel._queries), 0)

Expand Down
9 changes: 9 additions & 0 deletions tests/panels/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def test_custom_context_processor(self):
self.panel.process_response(self.request, self.response)
self.assertIn('tests.panels.test_template.context_processor', self.panel.content)

def test_disabled(self):
config = {
'DISABLE_PANELS': set([
'debug_toolbar.panels.templates.TemplatesPanel'])
}
self.assertTrue(self.panel.enabled)
with self.settings(DEBUG_TOOLBAR_CONFIG=config):
self.assertFalse(self.panel.enabled)


def context_processor(request):
return {'content': 'set by processor'}

0 comments on commit 30e56bf

Please sign in to comment.