diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 54a49e4d6..291fc94e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,13 +44,13 @@ repos: args: - --fix - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.5.0' + rev: 'v0.5.1' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.1.3 + rev: 2.1.4 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject diff --git a/README.rst b/README.rst index 4e195a796..362df2f95 100644 --- a/README.rst +++ b/README.rst @@ -44,7 +44,7 @@ Here's a screenshot of the toolbar in action: In addition to the built-in panels, a number of third-party panels are contributed by the community. -The current stable version of the Debug Toolbar is 4.4.5. It works on +The current stable version of the Debug Toolbar is 4.4.6. It works on Django ≥ 4.2.0. The Debug Toolbar does not currently support `Django's asynchronous views diff --git a/debug_toolbar/__init__.py b/debug_toolbar/__init__.py index a1a09f2a1..d98d6efae 100644 --- a/debug_toolbar/__init__.py +++ b/debug_toolbar/__init__.py @@ -4,7 +4,7 @@ # Do not use pkg_resources to find the version but set it here directly! # see issue #1446 -VERSION = "4.4.5" +VERSION = "4.4.6" # Code that discovers files or modules in INSTALLED_APPS imports this module. urls = "debug_toolbar.urls", APP_NAME diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 65b5282c5..b089d1484 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -11,9 +11,7 @@ from debug_toolbar import settings as dt_settings from debug_toolbar.toolbar import DebugToolbar -from debug_toolbar.utils import clear_stack_trace_caches - -_HTML_TYPES = ("text/html", "application/xhtml+xml") +from debug_toolbar.utils import clear_stack_trace_caches, is_processable_html_response def show_toolbar(request): @@ -102,13 +100,7 @@ def __call__(self, request): response.headers[header] = value # Check for responses where the toolbar can't be inserted. - content_encoding = response.get("Content-Encoding", "") - content_type = response.get("Content-Type", "").split(";")[0] - if ( - getattr(response, "streaming", False) - or content_encoding != "" - or content_type not in _HTML_TYPES - ): + if not is_processable_html_response(response): return response # Insert the toolbar in the response. diff --git a/debug_toolbar/panels/alerts.py b/debug_toolbar/panels/alerts.py index e640dcdd5..51334820d 100644 --- a/debug_toolbar/panels/alerts.py +++ b/debug_toolbar/panels/alerts.py @@ -3,6 +3,7 @@ from django.utils.translation import gettext_lazy as _ from debug_toolbar.panels import Panel +from debug_toolbar.utils import is_processable_html_response class FormParser(HTMLParser): @@ -138,8 +139,7 @@ def check_invalid_file_form_configuration(self, html_content): return self.alerts def generate_stats(self, request, response): - # check if streaming response - if getattr(response, "streaming", True): + if not is_processable_html_response(response): return html_content = response.content.decode(response.charset) diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index 3a9d0882e..1e75cced2 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -353,3 +353,16 @@ def get_stack_trace(*, skip=0): def clear_stack_trace_caches(): if hasattr(_local_data, "stack_trace_recorder"): del _local_data.stack_trace_recorder + + +_HTML_TYPES = ("text/html", "application/xhtml+xml") + + +def is_processable_html_response(response): + content_encoding = response.get("Content-Encoding", "") + content_type = response.get("Content-Type", "").split(";")[0] + return ( + not getattr(response, "streaming", False) + and content_encoding == "" + and content_type in _HTML_TYPES + ) diff --git a/docs/changes.rst b/docs/changes.rst index 952e6e996..e82c598c2 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,13 @@ Change log Pending ------- +4.4.6 (2024-07-10) +------------------ + +* Changed ordering (and grammatical number) of panels and their titles in + documentation to match actual panel ordering and titles. +* Skipped processing the alerts panel when response isn't a HTML response. + 4.4.5 (2024-07-05) ------------------ diff --git a/docs/conf.py b/docs/conf.py index 8b9d06396..924869c05 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ copyright = copyright.format(datetime.date.today().year) # The full version, including alpha/beta/rc tags -release = "4.4.5" +release = "4.4.6" # -- General configuration --------------------------------------------------- diff --git a/docs/panels.rst b/docs/panels.rst index c9ea6bbf0..7892dcf94 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -9,17 +9,6 @@ Default built-in panels The following panels are enabled by default. -Alerts -~~~~~~~ - -.. class:: debug_toolbar.panels.alerts.AlertsPanel - -This panel shows alerts for a set of pre-defined cases: - -- Alerts when the response has a form without the - ``enctype="multipart/form-data"`` attribute and the form contains - a file input. - History ~~~~~~~ @@ -33,8 +22,8 @@ snapshot of the toolbar to view that request's stats. ``True`` or if the server runs with multiple processes, the History Panel will be disabled. -Version -~~~~~~~ +Versions +~~~~~~~~ .. class:: debug_toolbar.panels.versions.VersionsPanel @@ -80,19 +69,30 @@ SQL SQL queries including time to execute and links to EXPLAIN each query. -Template -~~~~~~~~ +Static files +~~~~~~~~~~~~ + +.. class:: debug_toolbar.panels.staticfiles.StaticFilesPanel + +Used static files and their locations (via the ``staticfiles`` finders). + +Templates +~~~~~~~~~ .. class:: debug_toolbar.panels.templates.TemplatesPanel Templates and context used, and their template paths. -Static files -~~~~~~~~~~~~ +Alerts +~~~~~~~ -.. class:: debug_toolbar.panels.staticfiles.StaticFilesPanel +.. class:: debug_toolbar.panels.alerts.AlertsPanel -Used static files and their locations (via the ``staticfiles`` finders). +This panel shows alerts for a set of pre-defined cases: + +- Alerts when the response has a form without the + ``enctype="multipart/form-data"`` attribute and the form contains + a file input. Cache ~~~~~ @@ -101,8 +101,8 @@ Cache Cache queries. Is incompatible with Django's per-site caching. -Signal -~~~~~~ +Signals +~~~~~~~ .. class:: debug_toolbar.panels.signals.SignalsPanel diff --git a/tests/forms.py b/tests/forms.py index 9a4d38769..916cb6612 100644 --- a/tests/forms.py +++ b/tests/forms.py @@ -6,4 +6,4 @@ class TemplateReprForm(forms.Form): user = forms.ModelChoiceField(queryset=User.objects.all()) def __repr__(self): - return repr(self) + return str(self)