From 096fdf4ae9b442ccd6e43d27565f5a161d1e12e5 Mon Sep 17 00:00:00 2001 From: elineda Date: Mon, 15 Jan 2024 17:07:51 +0100 Subject: [PATCH 01/16] New AJAX request resets whole view if HistoryPanel is enabled [m] If history panel is activated and one previous request has been switched on any xhr or fetch will reset the whole view [m] The history panel is updated on click on the history button --- debug_toolbar/static/debug_toolbar/js/history.js | 3 +++ debug_toolbar/static/debug_toolbar/js/toolbar.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/static/debug_toolbar/js/history.js b/debug_toolbar/static/debug_toolbar/js/history.js index b30fcabae..be3f25fb2 100644 --- a/debug_toolbar/static/debug_toolbar/js/history.js +++ b/debug_toolbar/static/debug_toolbar/js/history.js @@ -76,6 +76,7 @@ function switchHistory(newStoreId) { const formTarget = djDebug.querySelector( ".switchHistory[data-store-id='" + newStoreId + "']" ); + djdt.history_storeId = newStoreId const tbody = formTarget.closest("tbody"); const highlighted = tbody.querySelector(".djdt-highlighted"); @@ -104,3 +105,5 @@ $$.on(djDebug, "click", ".refreshHistory", function (event) { event.preventDefault(); refreshHistory(); }); + +export { refreshHistory }; diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 9546ef27e..24a905bf7 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -1,4 +1,5 @@ import { $$, ajax, replaceToolbarState, debounce } from "./utils.js"; +import { refreshHistory } from "./history.js" function onKeyDown(event) { if (event.keyCode === 27) { @@ -19,6 +20,7 @@ const djdt = { handleDragged: false, init() { const djDebug = getDebugElement(); + console.log(djDebug) $$.on(djDebug, "click", "#djDebugPanelList li a", function (event) { event.preventDefault(); if (!this.className) { @@ -49,12 +51,16 @@ const djdt = { inner.previousElementSibling.remove(); // Remove AJAX loader inner.innerHTML = data.content; $$.executeScripts(data.scripts); + if (panelId == "HistoryPanel"){ + refreshHistory(); + } $$.applyStyles(inner); djDebug.dispatchEvent( new CustomEvent("djdt.panel.render", { detail: { panelId: panelId }, }) ); + }); } else { djDebug.dispatchEvent( @@ -62,6 +68,9 @@ const djdt = { detail: { panelId: panelId }, }) ); + if (panelId == "HistoryPanel"){ + refreshHistory(); + } } } }); @@ -274,7 +283,9 @@ const djdt = { storeId = encodeURIComponent(storeId); const dest = `${sidebarUrl}?store_id=${storeId}`; slowjax(dest).then(function (data) { - replaceToolbarState(storeId, data); + if (window.djdt.history_storeId == null){ + replaceToolbarState(storeId, data); + } }); } @@ -356,6 +367,7 @@ window.djdt = { init: djdt.init, close: djdt.hideOneLevel, cookie: djdt.cookie, + history_storeId: null, // StoreId if we choose to open a past request in the history }; if (document.readyState !== "loading") { From f499e415290dcf8d9a5f69794706aace8a9625eb Mon Sep 17 00:00:00 2001 From: elineda Date: Thu, 18 Jan 2024 20:35:05 +0100 Subject: [PATCH 02/16] New AJAX request resets whole view if HistoryPanel is enabled [m] Remove log --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 1 - 1 file changed, 1 deletion(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 24a905bf7..026d57c7e 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -20,7 +20,6 @@ const djdt = { handleDragged: false, init() { const djDebug = getDebugElement(); - console.log(djDebug) $$.on(djDebug, "click", "#djDebugPanelList li a", function (event) { event.preventDefault(); if (!this.className) { From 73c96ebfe0595736e10cb19158063419056511ee Mon Sep 17 00:00:00 2001 From: elineda Date: Tue, 23 Jan 2024 15:28:03 +0100 Subject: [PATCH 03/16] New AJAX request resets whole view if HistoryPanel is enabled [+] Create a settings which enable or disable the automatic refresh when an ajax request occurs --- debug_toolbar/settings.py | 1 + debug_toolbar/static/debug_toolbar/js/history.js | 4 +--- debug_toolbar/static/debug_toolbar/js/toolbar.js | 12 +++--------- debug_toolbar/templates/debug_toolbar/base.html | 2 +- docs/configuration.rst | 9 +++++++++ 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index eb6b59209..bbd155ecb 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -42,6 +42,7 @@ "SQL_WARNING_THRESHOLD": 500, # milliseconds "OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request", "TOOLBAR_LANGUAGE": None, + "UDPATE_ON_AJAX": False, } diff --git a/debug_toolbar/static/debug_toolbar/js/history.js b/debug_toolbar/static/debug_toolbar/js/history.js index be3f25fb2..23a72a264 100644 --- a/debug_toolbar/static/debug_toolbar/js/history.js +++ b/debug_toolbar/static/debug_toolbar/js/history.js @@ -76,7 +76,6 @@ function switchHistory(newStoreId) { const formTarget = djDebug.querySelector( ".switchHistory[data-store-id='" + newStoreId + "']" ); - djdt.history_storeId = newStoreId const tbody = formTarget.closest("tbody"); const highlighted = tbody.querySelector(".djdt-highlighted"); @@ -105,5 +104,4 @@ $$.on(djDebug, "click", ".refreshHistory", function (event) { event.preventDefault(); refreshHistory(); }); - -export { refreshHistory }; +$$.onPanelRender(djDebug, "HistoryPanel", refreshHistory); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 026d57c7e..afbcb5cb2 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -1,5 +1,4 @@ import { $$, ajax, replaceToolbarState, debounce } from "./utils.js"; -import { refreshHistory } from "./history.js" function onKeyDown(event) { if (event.keyCode === 27) { @@ -20,6 +19,7 @@ const djdt = { handleDragged: false, init() { const djDebug = getDebugElement(); + window.djdt.update_on_ajax = djDebug.getAttribute("update-on-ajax") === "True" $$.on(djDebug, "click", "#djDebugPanelList li a", function (event) { event.preventDefault(); if (!this.className) { @@ -50,9 +50,6 @@ const djdt = { inner.previousElementSibling.remove(); // Remove AJAX loader inner.innerHTML = data.content; $$.executeScripts(data.scripts); - if (panelId == "HistoryPanel"){ - refreshHistory(); - } $$.applyStyles(inner); djDebug.dispatchEvent( new CustomEvent("djdt.panel.render", { @@ -67,9 +64,6 @@ const djdt = { detail: { panelId: panelId }, }) ); - if (panelId == "HistoryPanel"){ - refreshHistory(); - } } } }); @@ -282,7 +276,7 @@ const djdt = { storeId = encodeURIComponent(storeId); const dest = `${sidebarUrl}?store_id=${storeId}`; slowjax(dest).then(function (data) { - if (window.djdt.history_storeId == null){ + if (window.djdt.update_on_ajax){ replaceToolbarState(storeId, data); } }); @@ -366,7 +360,7 @@ window.djdt = { init: djdt.init, close: djdt.hideOneLevel, cookie: djdt.cookie, - history_storeId: null, // StoreId if we choose to open a past request in the history + update_on_ajax: false, }; if (document.readyState !== "loading") { diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index 5447970af..800360c6e 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -16,7 +16,7 @@ data-sidebar-url="{{ history_url }}" {% endif %} data-default-show="{% if toolbar.config.SHOW_COLLAPSED %}false{% else %}true{% endif %}" - {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }}> + {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }} update-on-ajax="{{ toolbar.config.UDPATE_ON_AJAX|safe }}">
  • {% trans "Hide" %} »
  • diff --git a/docs/configuration.rst b/docs/configuration.rst index 887608c6e..9204bfad0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -163,6 +163,15 @@ Toolbar options but want to render your application in French, you would set this to ``"en-us"`` and :setting:`LANGUAGE_CODE` to ``"fr"``. +.. _UDPATE_ON_AJAX: + +* ``UDPATE_ON_AJAX`` + + Default: ``False`` + + This setting specifies if the whole toolbar need to be refresh if an ajax + request is done. + Panel options ~~~~~~~~~~~~~ From def324a5d475f2d7ca769eacb63ce466aae4a260 Mon Sep 17 00:00:00 2001 From: elineda Date: Wed, 24 Jan 2024 13:56:02 +0100 Subject: [PATCH 04/16] New AJAX request resets whole view if HistoryPanel is enabled [t] Add Test --- tests/templates/ajax/ajax.html | 21 +++++++++++++++++++++ tests/test_integration.py | 18 ++++++++++++++++++ tests/urls.py | 1 + tests/views.py | 4 ++++ 4 files changed, 44 insertions(+) create mode 100644 tests/templates/ajax/ajax.html diff --git a/tests/templates/ajax/ajax.html b/tests/templates/ajax/ajax.html new file mode 100644 index 000000000..0f6391d40 --- /dev/null +++ b/tests/templates/ajax/ajax.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% block content %} +
    click for ajax
    + + +{% endblock %} diff --git a/tests/test_integration.py b/tests/test_integration.py index b77b7cede..1b7ddf352 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -749,3 +749,21 @@ def test_toolbar_language_will_render_to_locale_when_set_both(self): ) self.assertIn("Query", table.text) self.assertIn("Action", table.text) + + def test_ajax_dont_refresh(self): + self.get('/ajax/') + make_ajax = self.selenium.find_element(By.ID, "click_for_ajax") + make_ajax.click() + history_panel = self.selenium.find_element(By.ID, "djdt-HistoryPanel") + self.assertIn('/ajax/', history_panel.text) + self.assertNotIn('/json_view/', history_panel.text) + + @override_settings(DEBUG_TOOLBAR_CONFIG={"UDPATE_ON_AJAX": True}) + def test_ajax_refresh(self): + self.get('/ajax/') + make_ajax = self.selenium.find_element(By.ID, "click_for_ajax") + make_ajax.click() + history_panel = self.selenium.find_element(By.ID, "djdt-HistoryPanel") + self.assertNotIn('/ajax/', history_panel.text) + self.assertIn('/json_view/', history_panel.text) + diff --git a/tests/urls.py b/tests/urls.py index 6fc8811b7..f8929f1e8 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -21,6 +21,7 @@ path("cached_low_level_view/", views.cached_low_level_view), path("json_view/", views.json_view), path("redirect/", views.redirect_view), + path("ajax/", views.ajax_view), path("login_without_redirect/", LoginView.as_view(redirect_field_name=None)), path("admin/", admin.site.urls), path("__debug__/", include("debug_toolbar.urls")), diff --git a/tests/views.py b/tests/views.py index b2fd21c54..c7214029e 100644 --- a/tests/views.py +++ b/tests/views.py @@ -58,3 +58,7 @@ def listcomp_view(request): def redirect_view(request): return HttpResponseRedirect("/regular/redirect/") + + +def ajax_view(request): + return render(request, "ajax/ajax.html") From 150e11b6f0bf5b5420127571b71fb74bc5a463d5 Mon Sep 17 00:00:00 2001 From: elineda Date: Wed, 24 Jan 2024 14:00:40 +0100 Subject: [PATCH 05/16] New AJAX request resets whole view if HistoryPanel is enabled [+] Add change --- docs/changes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes.rst b/docs/changes.rst index 15c380ddd..5e581b3f0 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -17,6 +17,7 @@ Pending ``django.contrib.admindocs.utils.get_view_name``. * Switched from black to the `ruff formatter `__. +* Add a setting for refresh or not the toolbar if an ajax request occurs. 4.2.0 (2023-08-10) ------------------ From 0419cd75c8215d1a6aef28f150895601ba27f7ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:02:04 +0000 Subject: [PATCH 06/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 2 +- tests/test_integration.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index afbcb5cb2..cb620c814 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -19,7 +19,7 @@ const djdt = { handleDragged: false, init() { const djDebug = getDebugElement(); - window.djdt.update_on_ajax = djDebug.getAttribute("update-on-ajax") === "True" + window.djdt.update_on_ajax = djDebug.getAttribute("update-on-ajax") === "True"; $$.on(djDebug, "click", "#djDebugPanelList li a", function (event) { event.preventDefault(); if (!this.className) { diff --git a/tests/test_integration.py b/tests/test_integration.py index 1b7ddf352..5fe516035 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -751,19 +751,18 @@ def test_toolbar_language_will_render_to_locale_when_set_both(self): self.assertIn("Action", table.text) def test_ajax_dont_refresh(self): - self.get('/ajax/') + self.get("/ajax/") make_ajax = self.selenium.find_element(By.ID, "click_for_ajax") make_ajax.click() history_panel = self.selenium.find_element(By.ID, "djdt-HistoryPanel") - self.assertIn('/ajax/', history_panel.text) - self.assertNotIn('/json_view/', history_panel.text) + self.assertIn("/ajax/", history_panel.text) + self.assertNotIn("/json_view/", history_panel.text) @override_settings(DEBUG_TOOLBAR_CONFIG={"UDPATE_ON_AJAX": True}) def test_ajax_refresh(self): - self.get('/ajax/') + self.get("/ajax/") make_ajax = self.selenium.find_element(By.ID, "click_for_ajax") make_ajax.click() history_panel = self.selenium.find_element(By.ID, "djdt-HistoryPanel") - self.assertNotIn('/ajax/', history_panel.text) - self.assertIn('/json_view/', history_panel.text) - + self.assertNotIn("/ajax/", history_panel.text) + self.assertIn("/json_view/", history_panel.text) From c6d3b65cecd471507bb4904351686feb27991a96 Mon Sep 17 00:00:00 2001 From: elineda Date: Wed, 24 Jan 2024 14:22:36 +0100 Subject: [PATCH 07/16] Add ajax in spelling_wordlist.txt --- docs/spelling_wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index 7a15d9aeb..86b46c497 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -57,3 +57,4 @@ tox uWSGI unhashable validator +ajax From bd2a24e8c774ca264551e0ac7834fe472af9b005 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:22:51 +0000 Subject: [PATCH 08/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/spelling_wordlist.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index 86b46c497..436977bdc 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -6,6 +6,7 @@ Pympler Roboto Transifex Werkzeug +ajax async backend backends @@ -57,4 +58,3 @@ tox uWSGI unhashable validator -ajax From d23bbd241d8dd429ea4806aff0dbdf391a9d2e60 Mon Sep 17 00:00:00 2001 From: elineda Date: Wed, 24 Jan 2024 15:38:41 +0100 Subject: [PATCH 09/16] New AJAX request resets whole view if HistoryPanel is enabled --- debug_toolbar/settings.py | 2 +- debug_toolbar/static/debug_toolbar/js/history.js | 1 + debug_toolbar/static/debug_toolbar/js/toolbar.js | 6 +++--- debug_toolbar/templates/debug_toolbar/base.html | 2 +- docs/configuration.rst | 4 ++-- tests/test_integration.py | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index bbd155ecb..dee63b355 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -42,7 +42,7 @@ "SQL_WARNING_THRESHOLD": 500, # milliseconds "OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request", "TOOLBAR_LANGUAGE": None, - "UDPATE_ON_AJAX": False, + "UPDATE_ON_FETCH": True, } diff --git a/debug_toolbar/static/debug_toolbar/js/history.js b/debug_toolbar/static/debug_toolbar/js/history.js index 23a72a264..4f6ff4a08 100644 --- a/debug_toolbar/static/debug_toolbar/js/history.js +++ b/debug_toolbar/static/debug_toolbar/js/history.js @@ -104,4 +104,5 @@ $$.on(djDebug, "click", ".refreshHistory", function (event) { event.preventDefault(); refreshHistory(); }); +// As we don't refresh the whole toolbar each fetch or ajax request we need to refresh the history when we open the panel $$.onPanelRender(djDebug, "HistoryPanel", refreshHistory); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index cb620c814..1a31b0478 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -17,9 +17,10 @@ function getDebugElement() { const djdt = { handleDragged: false, + needUpdateOnFetch: false, init() { const djDebug = getDebugElement(); - window.djdt.update_on_ajax = djDebug.getAttribute("update-on-ajax") === "True"; + djdt.needUpdateOnFetch = djDebug.dataset.updateOnFetch === "True"; $$.on(djDebug, "click", "#djDebugPanelList li a", function (event) { event.preventDefault(); if (!this.className) { @@ -276,7 +277,7 @@ const djdt = { storeId = encodeURIComponent(storeId); const dest = `${sidebarUrl}?store_id=${storeId}`; slowjax(dest).then(function (data) { - if (window.djdt.update_on_ajax){ + if (djdt.needUpdateOnFetch){ replaceToolbarState(storeId, data); } }); @@ -360,7 +361,6 @@ window.djdt = { init: djdt.init, close: djdt.hideOneLevel, cookie: djdt.cookie, - update_on_ajax: false, }; if (document.readyState !== "loading") { diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index 800360c6e..133163b6b 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -16,7 +16,7 @@ data-sidebar-url="{{ history_url }}" {% endif %} data-default-show="{% if toolbar.config.SHOW_COLLAPSED %}false{% else %}true{% endif %}" - {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }} update-on-ajax="{{ toolbar.config.UDPATE_ON_AJAX|safe }}"> + {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }} data-update-on-fetch="{{ toolbar.config.UPDATE_ON_FETCH|safe }}">
    • {% trans "Hide" %} »
    • diff --git a/docs/configuration.rst b/docs/configuration.rst index 9204bfad0..b2644993a 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -163,9 +163,9 @@ Toolbar options but want to render your application in French, you would set this to ``"en-us"`` and :setting:`LANGUAGE_CODE` to ``"fr"``. -.. _UDPATE_ON_AJAX: +.. _UPDATE_ON_FETCH: -* ``UDPATE_ON_AJAX`` +* ``UPDATE_ON_FETCH`` Default: ``False`` diff --git a/tests/test_integration.py b/tests/test_integration.py index 5fe516035..70989551e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -758,7 +758,7 @@ def test_ajax_dont_refresh(self): self.assertIn("/ajax/", history_panel.text) self.assertNotIn("/json_view/", history_panel.text) - @override_settings(DEBUG_TOOLBAR_CONFIG={"UDPATE_ON_AJAX": True}) + @override_settings(DEBUG_TOOLBAR_CONFIG={"UPDATE_ON_FETCH": True}) def test_ajax_refresh(self): self.get("/ajax/") make_ajax = self.selenium.find_element(By.ID, "click_for_ajax") From 4cb79005c7f7d6e93845d76883e8dd2c3dd5dd1a Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Thu, 25 Jan 2024 13:43:37 -0600 Subject: [PATCH 10/16] Documentation suggestions --- debug_toolbar/static/debug_toolbar/js/history.js | 3 ++- debug_toolbar/static/debug_toolbar/js/toolbar.js | 1 - docs/changes.rst | 4 +++- docs/configuration.rst | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/history.js b/debug_toolbar/static/debug_toolbar/js/history.js index 4f6ff4a08..314ddb3ef 100644 --- a/debug_toolbar/static/debug_toolbar/js/history.js +++ b/debug_toolbar/static/debug_toolbar/js/history.js @@ -104,5 +104,6 @@ $$.on(djDebug, "click", ".refreshHistory", function (event) { event.preventDefault(); refreshHistory(); }); -// As we don't refresh the whole toolbar each fetch or ajax request we need to refresh the history when we open the panel +// We don't refresh the whole toolbar each fetch or ajax request, +// so we need to refresh the history when we open the panel $$.onPanelRender(djDebug, "HistoryPanel", refreshHistory); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 96dbce2b1..199616336 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -57,7 +57,6 @@ const djdt = { detail: { panelId: panelId }, }) ); - }); } else { djDebug.dispatchEvent( diff --git a/docs/changes.rst b/docs/changes.rst index 1bb5e05b8..c20ca6adf 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -19,7 +19,9 @@ Pending `__. * Changed the default position of the toolbar from top to the upper top position. -* Add a setting for refresh or not the toolbar if an ajax request occurs. +* Added the setting, ``UPDATE_ON_FETCH`` to control whether the + toolbar automatically updates to the latest AJAX request or not. + It defaults to ``False``. 4.2.0 (2023-08-10) ------------------ diff --git a/docs/configuration.rst b/docs/configuration.rst index b2644993a..257d2eca0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -169,8 +169,9 @@ Toolbar options Default: ``False`` - This setting specifies if the whole toolbar need to be refresh if an ajax - request is done. + This controls whether the toolbar should update to the latest AJAX request when it occurs. + This is useful to enable if when "boosting" the web application with a JavaScript library such + as htmx. Panel options ~~~~~~~~~~~~~ From 20fad64309706dc06959177b7ef26077d07b7919 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 19:43:47 +0000 Subject: [PATCH 11/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/changes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index c20ca6adf..9ff88b2b8 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -19,7 +19,7 @@ Pending `__. * Changed the default position of the toolbar from top to the upper top position. -* Added the setting, ``UPDATE_ON_FETCH`` to control whether the +* Added the setting, ``UPDATE_ON_FETCH`` to control whether the toolbar automatically updates to the latest AJAX request or not. It defaults to ``False``. From 59e6a28398db99e6f321291ed8fdf205bce5acc0 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Thu, 25 Jan 2024 13:46:26 -0600 Subject: [PATCH 12/16] Update for line lengths. --- docs/configuration.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 257d2eca0..9f2383616 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -169,9 +169,9 @@ Toolbar options Default: ``False`` - This controls whether the toolbar should update to the latest AJAX request when it occurs. - This is useful to enable if when "boosting" the web application with a JavaScript library such - as htmx. + This controls whether the toolbar should update to the latest AJAX + request when it occurs. This is useful to enable if when "boosting" + the web application with a JavaScript library such as htmx. Panel options ~~~~~~~~~~~~~ From 43a6966a9c808417a6dcf89f731ec252b36cdc62 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Fri, 26 Jan 2024 14:48:40 -0600 Subject: [PATCH 13/16] Clean-up Tim's English in the changelog --- docs/configuration.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 9f2383616..8271092ca 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -170,8 +170,8 @@ Toolbar options Default: ``False`` This controls whether the toolbar should update to the latest AJAX - request when it occurs. This is useful to enable if when "boosting" - the web application with a JavaScript library such as htmx. + request when it occurs. This is especially useful when using htmx + boosting or similar JavaScript techniques. Panel options ~~~~~~~~~~~~~ From ba03e9fbd7b59d2fd2148774b0d83e812d18bb07 Mon Sep 17 00:00:00 2001 From: elineda Date: Mon, 29 Jan 2024 11:04:11 +0100 Subject: [PATCH 14/16] New AJAX request resets whole view if HistoryPanel is enabled [m] Remove safe on data-update-on-fetch attribute [m] Put the new settings as False as default like intended --- debug_toolbar/settings.py | 2 +- debug_toolbar/templates/debug_toolbar/base.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index dee63b355..1df24527d 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -42,7 +42,7 @@ "SQL_WARNING_THRESHOLD": 500, # milliseconds "OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request", "TOOLBAR_LANGUAGE": None, - "UPDATE_ON_FETCH": True, + "UPDATE_ON_FETCH": False, } diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index 133163b6b..6f4967f21 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -16,7 +16,7 @@ data-sidebar-url="{{ history_url }}" {% endif %} data-default-show="{% if toolbar.config.SHOW_COLLAPSED %}false{% else %}true{% endif %}" - {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }} data-update-on-fetch="{{ toolbar.config.UPDATE_ON_FETCH|safe }}"> + {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }} data-update-on-fetch="{{ toolbar.config.UPDATE_ON_FETCH }}">
      • {% trans "Hide" %} »
      • From 0fa76475225b012bac137779d9a68c3d4796a0bf Mon Sep 17 00:00:00 2001 From: elineda Date: Mon, 29 Jan 2024 12:12:00 +0100 Subject: [PATCH 15/16] New AJAX request resets whole view if HistoryPanel is enabled [t] Add a sleep on a selenium for prevent failure --- tests/templates/ajax/ajax.html | 2 +- tests/test_integration.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/templates/ajax/ajax.html b/tests/templates/ajax/ajax.html index 0f6391d40..c9de3acb6 100644 --- a/tests/templates/ajax/ajax.html +++ b/tests/templates/ajax/ajax.html @@ -4,7 +4,7 @@