Skip to content

Commit 4cadf08

Browse files
committed
Correct RENDER_PANELS functionality and when enabled disable HistoryPanel.
The render panels setting used to control whether the toolbar would keep the contents of the panels in the background or render the toolbar on every page. The history panel relies on loading panels in the background. If panels should be rendered on the request, then the history panel is can't/shouldn't work.
1 parent 3dc5437 commit 4cadf08

File tree

9 files changed

+72
-7
lines changed

9 files changed

+72
-7
lines changed

debug_toolbar/panels/history/panel.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class HistoryPanel(Panel):
2020
nav_title = _("History")
2121
template = "debug_toolbar/panels/history.html"
2222

23+
@property
24+
def enabled(self):
25+
# Do not show the history panel if the panels are rendered on request
26+
# rather than loaded via ajax.
27+
return super().enabled and not self.toolbar.should_render_panels()
28+
2329
@property
2430
def is_historical(self):
2531
"""The HistoryPanel should not be included in the historical panels."""

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<script type="module" src="{% static 'debug_toolbar/js/toolbar.js' %}" async></script>
88
{% endblock %}
99
<div id="djDebug" class="djdt-hidden" dir="ltr"
10-
{% if toolbar.store_id %}data-store-id="{{ toolbar.store_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"{% endif %}
10+
{% if not toolbar.should_render_panels %}
11+
data-store-id="{{ toolbar.store_id }}"
12+
data-render-panel-url="{% url 'djdt:render_panel' %}"
13+
{% endif %}
1114
data-default-show="{% if toolbar.config.SHOW_COLLAPSED %}false{% else %}true{% endif %}"
1215
{{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }}>
1316
<div class="djdt-hidden" id="djDebugToolbar">

debug_toolbar/templates/debug_toolbar/includes/panel_content.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<h3>{{ panel.title }}</h3>
88
</div>
99
<div class="djDebugPanelContent">
10-
{% if toolbar.store_id %}
10+
{% if toolbar.should_render_panels %}
11+
<div class="djdt-scroll">{{ panel.content }}</div>
12+
{% else %}
1113
<div class="djdt-loader"></div>
1214
<div class="djdt-scroll"></div>
13-
{% else %}
14-
<div class="djdt-scroll">{{ panel.content }}</div>
1515
{% endif %}
1616
</div>
1717
</div>

debug_toolbar/toolbar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def render_toolbar(self):
7878
raise
7979

8080
def should_render_panels(self):
81+
"""Determine whether the panels should be rendered during the request
82+
83+
If False, the panels will be loaded via Ajax.
84+
"""
8185
render_panels = self.config["RENDER_PANELS"]
8286
if render_panels is None:
8387
render_panels = self.request.META["wsgi.multiprocess"]

docs/changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Next version
99
* Added ``PRETTIFY_SQL`` configuration option to support controlling
1010
SQL token grouping. By default it's set to True. When set to False,
1111
a performance improvement can be seen by the SQL panel.
12+
* ``HistoryPanel`` will be disabled when ``RENDER_PANELS`` is ``True``
13+
or if it's not set, but the server is running with multiple processes.
14+
* Fixes ``RENDER_PANELS`` functionality so that when ``True`` panels are
15+
rendered during the request and not loaded asynchronously.
1216

1317

1418
3.2 (2020-12-03)

docs/configuration.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Toolbar options
6666
The toolbar searches for this string in the HTML and inserts itself just
6767
before.
6868

69+
.. _RENDER_PANELS:
70+
6971
* ``RENDER_PANELS``
7072

7173
Default: ``None``

docs/installation.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,11 @@ And for Apache:
147147
.. _JavaScript module: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
148148
.. _CORS errors: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin
149149
.. _Access-Control-Allow-Origin header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
150+
151+
Django Channels & Async
152+
^^^^^^^^^^^^^^^^^^^^^^^
153+
154+
The Debug Toolbar currently doesn't support Django Channels or async projects.
155+
If you are using Django channels are having issues getting panels to load,
156+
please review the documentation for the configuration option
157+
:ref:`RENDER_PANELS <RENDER_PANELS>`.

docs/panels.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ History
1717
This panel shows the history of requests made and allows switching to a past
1818
snapshot of the toolbar to view that request's stats.
1919

20+
.. caution::
21+
If :ref:`RENDER_PANELS <RENDER_PANELS>` configuration option is set to
22+
``True`` or if the server runs with multiple processes, the History Panel
23+
will be disabled.
24+
2025
Version
2126
~~~~~~~
2227

@@ -184,9 +189,9 @@ URL: https://github.com/danyi1212/django-windowsauth
184189

185190
Path: ``windows_auth.panels.LDAPPanel``
186191

187-
LDAP Operations performed during the request, including timing, request and response messages,
192+
LDAP Operations performed during the request, including timing, request and response messages,
188193
the entries received, write changes list, stack-tracing and error debugging.
189-
This panel also shows connection usage metrics when it is collected.
194+
This panel also shows connection usage metrics when it is collected.
190195
`Check out the docs <https://django-windowsauth.readthedocs.io/en/latest/howto/debug_toolbar.html>`_.
191196

192197
Line Profiler

tests/test_integration.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,44 @@ def test_sql_profile_checks_show_toolbar(self):
289289
self.assertEqual(response.status_code, 404)
290290

291291
@override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": True})
292-
def test_data_store_id_not_rendered_when_none(self):
292+
def test_render_panels_in_request(self):
293+
"""
294+
Test that panels are are rendered during the request with
295+
RENDER_PANELS=TRUE
296+
"""
293297
url = "/regular/basic/"
294298
response = self.client.get(url)
295299
self.assertIn(b'id="djDebug"', response.content)
300+
# Verify the store id is not included.
296301
self.assertNotIn(b"data-store-id", response.content)
302+
# Verify the history panel was disabled
303+
self.assertIn(
304+
b'<input type="checkbox" data-cookie="djdtHistoryPanel" '
305+
b'title="Enable for next and successive requests">',
306+
response.content,
307+
)
308+
# Verify the a panel was rendered
309+
self.assertIn(b"Response headers", response.content)
310+
311+
@override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": False})
312+
def test_load_panels(self):
313+
"""
314+
Test that panels are not rendered during the request with
315+
RENDER_PANELS=False
316+
"""
317+
url = "/execute_sql/"
318+
response = self.client.get(url)
319+
self.assertIn(b'id="djDebug"', response.content)
320+
# Verify the store id is included.
321+
self.assertIn(b"data-store-id", response.content)
322+
# Verify the history panel was not disabled
323+
self.assertNotIn(
324+
b'<input type="checkbox" data-cookie="djdtHistoryPanel" '
325+
b'title="Enable for next and successive requests">',
326+
response.content,
327+
)
328+
# Verify the a panel was not rendered
329+
self.assertNotIn(b"Response headers", response.content)
297330

298331
def test_view_returns_template_response(self):
299332
response = self.client.get("/template_response/basic/")

0 commit comments

Comments
 (0)