Skip to content

Commit f138780

Browse files
adamantiketim-schilling
authored andcommitted
fix: Simplify logic for Panel.enabled property
With this change, having a panel status set in the cookies exits earlier, as it isn't needed to retrieve the Django settings and panel name to calculate the default value.
1 parent 9f0b938 commit f138780

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

debug_toolbar/panels/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@ def panel_id(self):
2020
return self.__class__.__name__
2121

2222
@property
23-
def enabled(self):
23+
def enabled(self) -> bool:
24+
# The user's cookies should override the default value
25+
cookie_value = self.toolbar.request.COOKIES.get("djdt" + self.panel_id)
26+
if cookie_value is not None:
27+
return cookie_value == "on"
28+
2429
# Check to see if settings has a default value for it
2530
disabled_panels = dt_settings.get_config()["DISABLE_PANELS"]
2631
panel_path = get_name_from_obj(self)
2732
# Some panels such as the SQLPanel and TemplatesPanel exist in a
2833
# panel module, but can be disabled without panel in the path.
2934
# For that reason, replace .panel. in the path and check for that
3035
# value in the disabled panels as well.
31-
disable_panel = (
32-
panel_path in disabled_panels
33-
or panel_path.replace(".panel.", ".") in disabled_panels
36+
return (
37+
panel_path not in disabled_panels
38+
and panel_path.replace(".panel.", ".") not in disabled_panels
3439
)
35-
if disable_panel:
36-
default = "off"
37-
else:
38-
default = "on"
39-
# The user's cookies should override the default value
40-
return self.toolbar.request.COOKIES.get("djdt" + self.panel_id, default) == "on"
4140

4241
# Titles and content
4342

0 commit comments

Comments
 (0)