Skip to content

Commit d4e5ef9

Browse files
committed
Add a checkbox to toggle panels from the frontend.
Fix #35.
1 parent 30180ec commit d4e5ef9

File tree

7 files changed

+45
-17
lines changed

7 files changed

+45
-17
lines changed

debug_toolbar/middleware.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def process_request(self, request):
9292

9393
toolbar = DebugToolbar(request)
9494
for panel in toolbar.panels:
95+
panel.disabled = panel.dom_id() in request.COOKIES
96+
panel.enabled = not panel.disabled
97+
if panel.disabled:
98+
continue
9599
panel.process_request(request)
96100
self.__class__.debug_toolbars[threading.current_thread().ident] = toolbar
97101

@@ -102,6 +106,8 @@ def process_view(self, request, view_func, view_args, view_kwargs):
102106
return
103107
result = None
104108
for panel in toolbar.panels:
109+
if panel.disabled:
110+
continue
105111
response = panel.process_view(request, view_func, view_args, view_kwargs)
106112
if response:
107113
result = response
@@ -128,6 +134,8 @@ def process_response(self, request, response):
128134
if ('gzip' not in response.get('Content-Encoding', '') and
129135
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES):
130136
for panel in toolbar.panels:
137+
if panel.disabled:
138+
continue
131139
panel.process_response(request, response)
132140
response.content = replace_insensitive(
133141
force_text(response.content, encoding=settings.DEFAULT_CHARSET),

debug_toolbar/static/debug_toolbar/css/toolbar.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@
120120
width:auto;
121121
}
122122

123+
#djDebug #djDebugToolbar input[type=checkbox] {
124+
float: right;
125+
margin: 10px;
126+
}
127+
123128
#djDebug #djDebugToolbar li>a,
124129
#djDebug #djDebugToolbar li>div.contentless {
125130
font-weight:normal;
@@ -130,6 +135,10 @@
130135
padding:10px 10px 5px 25px;
131136
color:#fff;
132137
}
138+
#djDebug #djDebugToolbar li>div.disabled {
139+
font-style: italic;
140+
color: #999;
141+
}
133142

134143
#djDebug #djDebugToolbar li a:hover {
135144
color:#111;

debug_toolbar/static/debug_toolbar/css/toolbar.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ window.djdt = (function(window, document, jQuery) {
3535
$('#djDebugToolbar li').removeClass('active');
3636
return false;
3737
});
38+
$('#djDebug .djDebugPanelButton input[type=checkbox]').live('click', function() {
39+
$.cookie($(this).attr('data-cookie'), 'off', {
40+
path: '/',
41+
expires: $(this).prop('checked') ? -1 : 10
42+
});
43+
});
3844

3945
$('#djDebug .remoteCall').live('click', function() {
4046
var self = $(this);
@@ -257,13 +263,13 @@ window.djdt = (function(window, document, jQuery) {
257263
var $row = $('<tr class="' + ((rowCount % 2) ? 'djDebugOdd' : 'djDebugEven') + '"></tr>');
258264
if (endStat) {
259265
// Render a start through end bar
260-
$row.html('<td>' + stat.replace('Start', '') + '</td>' +
261-
'<td class="timeline"><div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:' + getCSSWidth(stat, endStat) + ';">&nbsp;</strong></div></div></td>' +
266+
$row.html('<td>' + stat.replace('Start', '') + '</td>' +
267+
'<td class="timeline"><div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:' + getCSSWidth(stat, endStat) + ';">&nbsp;</strong></div></div></td>' +
262268
'<td>' + (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ')</td>');
263269
} else {
264270
// Render a point in time
265-
$row.html('<td>' + stat + '</td>' +
266-
'<td class="timeline"><div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:2px;">&nbsp;</strong></div></div></td>' +
271+
$row.html('<td>' + stat + '</td>' +
272+
'<td class="timeline"><div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:2px;">&nbsp;</strong></div></div></td>' +
267273
'<td>' + (perf.timing[stat] - timingOffset) + '</td>');
268274
}
269275
$('#djDebugBrowserTimingTableBody').append($row);

debug_toolbar/static/debug_toolbar/js/toolbar.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
{% endif %}
1515
{% for panel in panels %}
1616
<li class="djDebugPanelButton">
17-
{% if panel.has_content %}
17+
<input type="checkbox" data-cookie="{{ panel.dom_id }}"{% if panel.enabled %} checked="checked"{% endif %} title="{% trans "Toogle Panel" %}" />
18+
{% if panel.has_content and panel.enabled %}
1819
<a href="{{ panel.url|default:"#" }}" title="{{ panel.title }}" class="{{ panel.dom_id }}">
1920
{% else %}
20-
<div class="contentless">
21+
<div class="contentless{% if panel.disabled %} disabled{% endif %}">
2122
{% endif %}
2223
{{ panel.nav_title }}
24+
{% if panel.enabled %}
2325
{% with panel.nav_subtitle as subtitle %}
2426
{% if subtitle %}<br /><small>{{ subtitle }}</small>{% endif %}
2527
{% endwith %}
26-
{% if panel.has_content %}
28+
{% endif %}
29+
{% if panel.has_content and panel.enabled %}
2730
</a>
2831
{% else %}
2932
</div>
@@ -36,7 +39,7 @@
3639
<a title="{% trans "Show Toolbar" %}" id="djShowToolBarButton" href="#">&#171;</a>
3740
</div>
3841
{% for panel in panels %}
39-
{% if panel.has_content %}
42+
{% if panel.has_content and panel.enabled %}
4043
<div id="{{ panel.dom_id }}" class="panelContent">
4144
<div class="djDebugPanelTitle">
4245
<a href="" class="djDebugClose">{% trans "Close" %}</a>

docs/tips.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Performance considerations
66

77
The Debug Toolbar adds some overhead to the rendering of each page. Depending
88
on your project, this overhead may slow down page loads significantly. If that
9-
makes development impractical, you can tune some settings to disable the most
10-
expensive features and restore decent response times.
9+
makes development impractical, you can disable the most expensive features to
10+
restore decent response times.
1111

1212
The SQL panel may be the culprit if your view performs many SQL queries. You
1313
should attempt to minimize the number of SQL queries, but this isn't always
@@ -24,6 +24,8 @@ large contexts and your templates have complex inheritance or inclusion
2424
schemes. In that case, you should set ``SHOW_TEMPLATE_CONTEXT`` to ``False``
2525
in the ``DEBUG_TOOLBAR_CONFIG`` setting.
2626

27-
Finally, if you don't need the panels that are slowing down your application,
28-
you can customize the ``DEBUG_TOOLBAR_PANELS`` setting to include only the
29-
panels you actually use.
27+
If you don't need the panels that are slowing down your application, you can
28+
disable them temporarily by deselecting the checkbox at the top right of each
29+
panel. Depending on implementation details, there may be a residual overhead.
30+
To remove them entirely, you can customize the ``DEBUG_TOOLBAR_PANELS``
31+
setting to include only the panels you actually use.

0 commit comments

Comments
 (0)