mirror of
https://github.com/django/django.git
synced 2025-03-31 19:46:42 +00:00
Fixed #29270 -- Fixed UserChangeForm crash if password field is excluded.
This commit is contained in:
parent
c59aa9e6aa
commit
874977d388
@ -137,10 +137,12 @@ class UserChangeForm(forms.ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['password'].help_text = self.fields['password'].help_text.format('../password/')
|
password = self.fields.get('password')
|
||||||
f = self.fields.get('user_permissions')
|
if password:
|
||||||
if f is not None:
|
password.help_text = password.help_text.format('../password/')
|
||||||
f.queryset = f.queryset.select_related('content_type')
|
user_permissions = self.fields.get('user_permissions')
|
||||||
|
if user_permissions:
|
||||||
|
user_permissions.queryset = user_permissions.queryset.select_related('content_type')
|
||||||
|
|
||||||
def clean_password(self):
|
def clean_password(self):
|
||||||
# Regardless of what the user provides, return the initial value.
|
# Regardless of what the user provides, return the initial value.
|
||||||
|
@ -797,6 +797,17 @@ class UserChangeFormTest(ReloadFormsMixin, TestDataMixin, TestCase):
|
|||||||
form = UserChangeForm(data, instance=user)
|
form = UserChangeForm(data, instance=user)
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_password_excluded(self):
|
||||||
|
class UserChangeFormWithoutPassword(UserChangeForm):
|
||||||
|
password = None
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
exclude = ['password']
|
||||||
|
|
||||||
|
form = UserChangeFormWithoutPassword()
|
||||||
|
self.assertNotIn('password', form.fields)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TEMPLATES=AUTH_TEMPLATES)
|
@override_settings(TEMPLATES=AUTH_TEMPLATES)
|
||||||
class PasswordResetFormTest(TestDataMixin, TestCase):
|
class PasswordResetFormTest(TestDataMixin, TestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user