Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions debug_toolbar/panels/redirects.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from inspect import iscoroutine

from django.template.response import SimpleTemplateResponse
Expand All @@ -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.
Expand Down
50 changes: 50 additions & 0 deletions debug_toolbar/static/debug_toolbar/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -1219,3 +1219,53 @@ To regenerate:
#djDebug .djdt-community-panel a:hover {
text-decoration: underline;
}

#djDebug .djdt-deprecation-warning {
--djdt-warning-bg: #fff3cd;
--djdt-warning-text: #856404;
--djdt-warning-accent: #f1c40f;
--djdt-warning-link: #0056b3;
--djdt-warning-link-hover: #003d7a;
--djdt-warning-strong: #000;
--djdt-warning-shadow: rgba(0, 0, 0, 0.1);

position: relative;
background-color: var(--djdt-warning-bg);
color: var(--djdt-warning-text);
border-left: 0.25em solid var(--djdt-warning-accent);
padding: 1em;
margin: 1.5em 0;
border-radius: 0.25em;
box-shadow:
0 0.0625em 0.1875em var(--djdt-warning-shadow),
0 0.0625em 0.125em var(--djdt-warning-shadow);
font-family: var(--djdt-font-family-primary);
font-size: 0.875em;
line-height: 1.5;
}

#djDebug .djdt-deprecation-warning::before {
content: "⚠️";
font-size: 1.125em;
margin-right: 0.75em;
vertical-align: middle;
}

#djDebug .djdt-deprecation-warning a {
color: var(--djdt-warning-link);
text-decoration: none;
font-weight: 500;
border-bottom: 0.0625em solid currentColor;
padding-bottom: 0.0625em;
transition: all 0.2s ease;
}

#djDebug .djdt-deprecation-warning a:hover {
color: var(--djdt-warning-link-hover);
border-bottom-width: 0.125em;
}

#djDebug .djdt-deprecation-warning strong {
color: var(--djdt-warning-strong);
font-weight: 600;
}
6 changes: 5 additions & 1 deletion debug_toolbar/templates/debug_toolbar/redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<head>
<title>Django Debug Toolbar Redirects Panel: {{ status_line }}</title>
<script{% if toolbar.csp_nonce %} nonce="{{ toolbar.csp_nonce }}"{% endif %} type="module" src="{% static 'debug_toolbar/js/redirect.js' %}" async></script>
<link{% if toolbar.csp_nonce %} nonce="{{ toolbar.csp_nonce }}"{% endif %} rel="stylesheet" href="{% static 'debug_toolbar/css/toolbar.css' %}">
</head>
<body>
<body id="djDebug" {% if toolbar.store_id %}data-store-id="{{ toolbar.store_id }}"{% endif %}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id="djDebug" seems to be causing downstream effects. I wonder if it'd be better to have the styles defined in the <head> here directly?

<div class="djdt-deprecation-warning">
<strong>{% translate "WARNING:" %}</strong> {% translate "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 <a href='https://github.com/django-commons/django-debug-toolbar/issues/2216'>issue</a>" %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<strong>{% translate "WARNING:" %}</strong> {% translate "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 <a href='https://github.com/django-commons/django-debug-toolbar/issues/2216'>issue</a>" %}
<strong>{% translate "WARNING:" %}</strong> {% translate "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 <a target='_blank' href='https://github.com/django-commons/django-debug-toolbar/issues/2216'>issue</a>" %}

I also think a {% blocktranslate %} may make this a bit more readable since you could add more linebreaks to the code.

</div>
<h1>{{ status_line }}</h1>
<h2>{% translate "Location:" %} <a id="redirect_to" href="{{ redirect_to }}">{{ redirect_to }}</a></h2>
<p class="notice">
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions docs/panels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/django-commons/django-debug-toolbar/issues/2216>`_.

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
Expand Down
18 changes: 18 additions & 0 deletions tests/panels/test_redirects.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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


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
Expand Down Expand Up @@ -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))