diff --git a/debug_toolbar/panels/redirects.py b/debug_toolbar/panels/redirects.py index 8055c67ad..1db439723 100644 --- a/debug_toolbar/panels/redirects.py +++ b/debug_toolbar/panels/redirects.py @@ -1,3 +1,4 @@ +import warnings from inspect import iscoroutine from django.template.response import SimpleTemplateResponse @@ -17,6 +18,17 @@ class RedirectsPanel(Panel): nav_title = _("Intercept redirects") + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + warnings.warn( + "The RedirectsPanel is deprecated and will be removed in a future version. " + "The HistoryPanel now provides the ability to view toolbar data for redirected requests. " + "If you still have a use case for this panel, please comment on " + "https://github.com/django-commons/django-debug-toolbar/issues/2216", + DeprecationWarning, + stacklevel=2, + ) + def _process_response(self, response): """ Common response processing logic. diff --git a/debug_toolbar/templates/debug_toolbar/redirect.html b/debug_toolbar/templates/debug_toolbar/redirect.html index 46897846d..cb2bef316 100644 --- a/debug_toolbar/templates/debug_toolbar/redirect.html +++ b/debug_toolbar/templates/debug_toolbar/redirect.html @@ -4,8 +4,71 @@ Django Debug Toolbar Redirects Panel: {{ status_line }} + + +
+ {% translate "WARNING:" %} + {% blocktranslate with issue_url="https://github.com/django-commons/django-debug-toolbar/issues/2216" %} + The RedirectsPanel is deprecated and will be removed in a future version. The HistoryPanel + now provides the ability to view toolbar data for redirected requests. If you still have a + use case for this panel, please comment on this issue. + {% endblocktranslate %} +

{{ status_line }}

{% translate "Location:" %} {{ redirect_to }}

diff --git a/docs/changes.rst b/docs/changes.rst index 667251b4f..d7c92cbee 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -16,6 +16,8 @@ Pending * Upgraded CI ``postgis`` version to 17-3.5. * Added how to generate the documentation locally to the contributing documentation. +* Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing + toolbar data from redirected requests. * Updated logic that forces values to strings (``force_str``) to render "Django Debug Toolbar was unable to parse value." when there's a decoding error. diff --git a/docs/panels.rst b/docs/panels.rst index f2364ea7c..5f1b37b4f 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -120,6 +120,13 @@ Redirects .. class:: debug_toolbar.panels.redirects.RedirectsPanel +.. deprecated:: 6.0 + +The RedirectsPanel is deprecated and will be removed in a future version. +The HistoryPanel now provides the ability to view toolbar data for redirected +requests. If you have a use case for this panel, please comment on the +GitHub issue `_. + When this panel is enabled, the debug toolbar will show an intermediate page upon redirect so you can view any debug information prior to redirecting. This page will provide a link to the redirect destination you can follow when diff --git a/tests/panels/test_redirects.py b/tests/panels/test_redirects.py index c81c7eaba..86622b157 100644 --- a/tests/panels/test_redirects.py +++ b/tests/panels/test_redirects.py @@ -1,10 +1,12 @@ import copy +import warnings from django.conf import settings from django.http import HttpResponse from django.test import AsyncRequestFactory from debug_toolbar.panels.redirects import RedirectsPanel +from debug_toolbar.toolbar import DebugToolbar from ..base import BaseTestCase @@ -12,6 +14,12 @@ class RedirectsPanelTestCase(BaseTestCase): panel_id = RedirectsPanel.panel_id + def setUp(self): + # Suppress the deprecation warning during setup + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + super().setUp() + def test_regular_response(self): not_redirect = HttpResponse() self._get_response = lambda request: not_redirect @@ -100,3 +108,13 @@ def test_original_response_preserved(self): self.assertEqual( response.original_response.get("Location"), "http://somewhere/else/" ) + + def test_deprecation_warning(self): + """Test that a deprecation warning is shown when RedirectsPanel is instantiated.""" + + with self.assertWarns(DeprecationWarning) as cm: + toolbar = DebugToolbar(self.request, self._get_response) + toolbar.get_panel_by_id(RedirectsPanel.panel_id) + + self.assertIn("RedirectsPanel is deprecated", str(cm.warning)) + self.assertIn("HistoryPanel", str(cm.warning))