Skip to content

Disable instrumentation for disabled panels #453

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

Merged
merged 4 commits into from
Nov 10, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove Panel.disabled, always use Panel.enabled.
  • Loading branch information
aaugustin committed Nov 10, 2013
commit 6a8526a93b60ebae214dbe0d4cbf172c311802b9
9 changes: 4 additions & 5 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ def process_request(self, request):

toolbar = DebugToolbar(request)
for panel in toolbar.panels:
panel.disabled = panel.dom_id() in request.COOKIES
panel.enabled = not panel.disabled
if panel.disabled:
panel.enabled = panel.dom_id() not in request.COOKIES
if not panel.enabled:
continue
panel.process_request(request)
self.__class__.debug_toolbars[threading.current_thread().ident] = toolbar
Expand All @@ -106,7 +105,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
return
result = None
for panel in toolbar.panels:
if panel.disabled:
if not panel.enabled:
continue
response = panel.process_view(request, view_func, view_args, view_kwargs)
if response:
Expand Down Expand Up @@ -134,7 +133,7 @@ def process_response(self, request, response):
if ('gzip' not in response.get('Content-Encoding', '') and
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES):
for panel in toolbar.panels:
if panel.disabled:
if not panel.enabled:
continue
panel.process_response(request, response)
response.content = replace_insensitive(
Expand Down
7 changes: 6 additions & 1 deletion debug_toolbar/panels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ class DebugPanel(object):
"""
# name = 'Base'
# template = 'debug_toolbar/panels/base.html'
has_content = False # If content returns something, set to True in subclass

# If content returns something, set to True in subclass
has_content = False

# This can be set to False in instances if the panel is disabled.
enabled = True

# We'll maintain a local context instance so we can expose our template
# context variables to panels which need them:
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% if panel.has_content and panel.enabled %}
<a href="{{ panel.url|default:"#" }}" title="{{ panel.title }}" class="{{ panel.dom_id }}">
{% else %}
<div class="contentless{% if panel.disabled %} disabled{% endif %}">
<div class="contentless{% if not panel.enabled %} disabled{% endif %}">
{% endif %}
{{ panel.nav_title }}
{% if panel.enabled %}
Expand Down