From 6a8526a93b60ebae214dbe0d4cbf172c311802b9 Mon Sep 17 00:00:00 2001
From: Aymeric Augustin
Date: Sun, 10 Nov 2013 15:18:29 +0100
Subject: [PATCH 1/4] Remove Panel.disabled, always use Panel.enabled.
---
debug_toolbar/middleware.py | 9 ++++-----
debug_toolbar/panels/__init__.py | 7 ++++++-
debug_toolbar/templates/debug_toolbar/base.html | 2 +-
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 7988fd523..4f5b9bd91 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -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
@@ -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:
@@ -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(
diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py
index eb3b21fff..d4a61dae1 100644
--- a/debug_toolbar/panels/__init__.py
+++ b/debug_toolbar/panels/__init__.py
@@ -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:
diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html
index d5a356cd9..616202001 100644
--- a/debug_toolbar/templates/debug_toolbar/base.html
+++ b/debug_toolbar/templates/debug_toolbar/base.html
@@ -24,7 +24,7 @@
{% if panel.has_content and panel.enabled %}
{% else %}
-