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

fix: Simplify logic for Panel.enabled property #1676

Merged
Merged
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
19 changes: 9 additions & 10 deletions debug_toolbar/panels/__init__.py
Expand Up @@ -20,24 +20,23 @@ def panel_id(self):
return self.__class__.__name__

@property
def enabled(self):
def enabled(self) -> bool:
# The user's cookies should override the default value
cookie_value = self.toolbar.request.COOKIES.get("djdt" + self.panel_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user has enabled a panel (creating a cookie value of "on"), then changes their settings file to disable it, wouldn't this override the customized settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, that's the same behavior we have today, as the default value is only used when a cookie value is not found in the request.

This shouldn't change how a panel status is decided, just to return faster when the cookie is set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct. DebugToolbar.get_panel_classes is what I was worried about. I wanted to make sure that a developer was still able to stop using a panel even if the cookies are set.

if cookie_value is not None:
return cookie_value == "on"

# Check to see if settings has a default value for it
disabled_panels = dt_settings.get_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
return (
panel_path not in disabled_panels
and panel_path.replace(".panel.", ".") not in disabled_panels
)
if disable_panel:
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

Expand Down