From 3f1bc2222feeaeaeaa97ba221b7d6e41962162e7 Mon Sep 17 00:00:00 2001 From: Yaser Amiri Date: Fri, 16 Jun 2023 14:08:34 +0330 Subject: [PATCH] Fixed #34656 -- Fixed unclosed div in admin password change template. Regression in 6991880109e35c879b71b7d9d9c154baeec12b89. --- .../admin/auth/user/change_password.html | 2 +- tests/admin_views/tests.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html index 5a5cc2ef27..ebb24ef562 100644 --- a/django/contrib/admin/templates/admin/auth/user/change_password.html +++ b/django/contrib/admin/templates/admin/auth/user/change_password.html @@ -34,7 +34,7 @@ {{ form.password1.errors }}
{{ form.password1.label_tag }} {{ form.password1 }}
{% if form.password1.help_text %} -
{% endif %}{{ form.password1.help_text|safe }}
+
{{ form.password1.help_text|safe }}
{% endif %} diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index b10cd1eab2..9fe5d589e6 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -6,6 +6,7 @@ import zoneinfo from unittest import mock from urllib.parse import parse_qsl, urljoin, urlparse +from django import forms from django.contrib import admin from django.contrib.admin import AdminSite, ModelAdmin from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME @@ -16,6 +17,8 @@ from django.contrib.admin.tests import AdminSeleniumTestCase from django.contrib.admin.utils import quote from django.contrib.admin.views.main import IS_POPUP_VAR from django.contrib.auth import REDIRECT_FIELD_NAME, get_permission_codename +from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.forms import AdminPasswordChangeForm from django.contrib.auth.models import Group, Permission, User from django.contrib.contenttypes.models import ContentType from django.core import mail @@ -25,6 +28,7 @@ from django.db import connection from django.forms.utils import ErrorList from django.template.response import TemplateResponse from django.test import ( + RequestFactory, TestCase, ignore_warnings, modify_settings, @@ -1652,6 +1656,29 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): "Enter the same password as before, for verification.", ) + def test_change_password_template_helptext_no_id(self): + user = User.objects.get(username="super") + + class EmptyIdForLabelTextInput(forms.TextInput): + def id_for_label(self, id): + return None + + class EmptyIdForLabelHelpTextPasswordChangeForm(AdminPasswordChangeForm): + password1 = forms.CharField( + help_text="Your new password", widget=EmptyIdForLabelTextInput() + ) + + class CustomUserAdmin(UserAdmin): + change_password_form = EmptyIdForLabelHelpTextPasswordChangeForm + + request = RequestFactory().get( + reverse("admin:auth_user_password_change", args=(user.id,)) + ) + request.user = user + user_admin = CustomUserAdmin(User, site) + response = user_admin.user_change_password(request, str(user.pk)) + self.assertContains(response, '
') + def test_extended_bodyclass_template_index(self): """ The admin/index.html template uses block.super in the bodyclass block.