Skip to content
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

Support disabling panels with the names in the docs. #708

Merged
merged 1 commit into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'}