From ed4c2e1c0d9e43c09767b02fd8b4bd74a5dfe512 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 24 Mar 2014 08:49:05 -0400 Subject: [PATCH] Fixed #22329 -- Used label_tag() in some admin auth templates. refs #17922. --- django/contrib/admin/forms.py | 7 ++++++- django/contrib/admin/sites.py | 2 ++ .../admin/templates/admin/auth/user/change_password.html | 6 ++---- django/contrib/admin/templates/admin/login.html | 4 ++-- .../admin/templates/registration/password_change_form.html | 6 +++--- django/contrib/auth/forms.py | 1 + 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/django/contrib/admin/forms.py b/django/contrib/admin/forms.py index f3ed7a8017..ede6f257ad 100644 --- a/django/contrib/admin/forms.py +++ b/django/contrib/admin/forms.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django import forms -from django.contrib.auth.forms import AuthenticationForm +from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm from django.utils.translation import ugettext_lazy as _ @@ -15,6 +15,7 @@ class AdminAuthenticationForm(AuthenticationForm): "for a staff account. Note that both fields may be " "case-sensitive."), } + required_css_class = 'required' def confirm_login_allowed(self, user): if not user.is_active or not user.is_staff: @@ -23,3 +24,7 @@ class AdminAuthenticationForm(AuthenticationForm): code='invalid_login', params={'username': self.username_field.verbose_name} ) + + +class AdminPasswordChangeForm(PasswordChangeForm): + required_css_class = 'required' diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index efac3c7521..2e1468b87a 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -273,10 +273,12 @@ class AdminSite(object): """ Handles the "change password" task -- both form display and validation. """ + from django.contrib.admin.forms import AdminPasswordChangeForm from django.contrib.auth.views import password_change url = reverse('admin:password_change_done', current_app=self.name) defaults = { 'current_app': self.name, + 'password_change_form': AdminPasswordChangeForm, 'post_change_redirect': url, 'extra_context': self.each_context(), } 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 cd11a2ee48..8bbc4484c0 100644 --- a/django/contrib/admin/templates/admin/auth/user/change_password.html +++ b/django/contrib/admin/templates/admin/auth/user/change_password.html @@ -34,14 +34,12 @@
{{ form.password1.errors }} - {# TODO: get required class on label_tag #} - {{ form.password1 }} + {{ form.password1.label_tag }} {{ form.password1 }}
{{ form.password2.errors }} - {# TODO: get required class on label_tag #} - {{ form.password2 }} + {{ form.password2.label_tag }} {{ form.password2 }}

{% trans 'Enter the same password as above, for verification.' %}

diff --git a/django/contrib/admin/templates/admin/login.html b/django/contrib/admin/templates/admin/login.html index bf1b3f9382..ce7ac30927 100644 --- a/django/contrib/admin/templates/admin/login.html +++ b/django/contrib/admin/templates/admin/login.html @@ -30,11 +30,11 @@
{% csrf_token %}
{{ form.username.errors }} - {{ form.username }} + {{ form.username.label_tag }} {{ form.username }}
{{ form.password.errors }} - {{ form.password }} + {{ form.password.label_tag }} {{ form.password }}
{% url 'admin_password_reset' as password_reset_url %} diff --git a/django/contrib/admin/templates/registration/password_change_form.html b/django/contrib/admin/templates/registration/password_change_form.html index 7b3ae6f6bf..6c1118de00 100644 --- a/django/contrib/admin/templates/registration/password_change_form.html +++ b/django/contrib/admin/templates/registration/password_change_form.html @@ -29,17 +29,17 @@
{{ form.old_password.errors }} - {{ form.old_password }} + {{ form.old_password.label_tag }} {{ form.old_password }}
{{ form.new_password1.errors }} - {{ form.new_password1 }} + {{ form.new_password1.label_tag }} {{ form.new_password1 }}
{{ form.new_password2.errors }} - {{ form.new_password2 }} + {{ form.new_password2.label_tag }} {{ form.new_password2 }}
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 6e07d45568..f1a0e095f4 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -348,6 +348,7 @@ class AdminPasswordChangeForm(forms.Form): error_messages = { 'password_mismatch': _("The two password fields didn't match."), } + required_css_class = 'required' password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput) password2 = forms.CharField(label=_("Password (again)"),