Skip to content

Commit 80071cc

Browse files
committed
Amended fix for django-commons#1682 -- added warning in nav_subtitle
1 parent d19bf7b commit 80071cc

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,23 @@ def title(self):
130130

131131
@property
132132
def nav_subtitle(self):
133+
subtitle_parts = []
133134
if self.templates:
134-
return self.templates[0]["template"].name
135-
return ""
135+
template_name = self.templates[0]["template"].name or "No template name"
136+
subtitle_parts.append(template_name)
137+
if self.invalid_file_form_configs_count:
138+
# Add warning for user indicating file form configuration issue
139+
issue_text = (
140+
"issue" if self.invalid_file_form_configs_count == 1 else "issues"
141+
)
142+
subtitle_parts.append(
143+
f"{self.invalid_file_form_configs_count} file form configuration "
144+
f"{issue_text} found"
145+
)
146+
if len(subtitle_parts) > 1:
147+
return " - ".join(subtitle_parts)
148+
else:
149+
return subtitle_parts[0] if subtitle_parts else ""
136150

137151
template = "debug_toolbar/panels/templates.html"
138152

@@ -260,6 +274,7 @@ def generate_stats(self, request, response):
260274
invalid_file_form_configs = self.check_invalid_file_form_configuration(
261275
html_content
262276
)
277+
self.invalid_file_form_configs_count = len(invalid_file_form_configs)
263278

264279
self.record_stats(
265280
{

tests/panels/test_template.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_file_form_without_enctype_multipart_form_data(self):
8181
'but missing enctype="multipart/form-data".'
8282
)
8383
self.assertEqual(result[0]["error_message"], expected_error)
84+
self.assertEqual(len(result), 1)
8485

8586
def test_file_form_with_enctype_multipart_form_data(self):
8687
test_form = """<form id="test-form" enctype="multipart/form-data">
@@ -90,6 +91,21 @@ def test_file_form_with_enctype_multipart_form_data(self):
9091

9192
self.assertEqual(len(result), 0)
9293

94+
def test_file_form_configuration_warning_display(self):
95+
"""
96+
Test that the panel (does not) display[s] a warning when there are (no)
97+
forms with file input types but encoding not set to multipart/form-data.
98+
"""
99+
# Should not show issue in subtitle when no invalid configurations
100+
self.panel.invalid_file_form_configs_count = 0
101+
nav_subtitle = self.panel.nav_subtitle
102+
self.assertNotIn("file form configuration issue", nav_subtitle)
103+
104+
# Should show issue in subtitle when invalid configurations
105+
self.panel.invalid_file_form_configs_count = 2
106+
nav_subtitle = self.panel.nav_subtitle
107+
self.assertIn("2 file form configuration issues found", nav_subtitle)
108+
93109
def test_insert_content(self):
94110
"""
95111
Test that the panel only inserts content after generate_stats and

0 commit comments

Comments
 (0)