summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorGary Jarrel <gary@jarrel.com.au>2023-03-27 23:26:06 +1100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-28 11:33:20 +0200
commitfcc7dc5781667932bf0bf8bec76df458836e5e95 (patch)
treeb863d20774080545ddf4b2b708c004738db21299 /django
parent45ecd9acca9b36093e274f47b6877a5f79108d9e (diff)
downloaddjango-fcc7dc5781667932bf0bf8bec76df458836e5e95.tar.gz
Fixed #34438 -- Reallowed extending UserCreationForm.
Regression in 298d02a77a69321af8c0023df3250663e9d1362d.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/auth/forms.py20
-rw-r--r--django/contrib/auth/locale/en/LC_MESSAGES/django.po8
2 files changed, 17 insertions, 11 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 0376d17709..eaae0bf695 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -147,16 +147,22 @@ class BaseUserCreationForm(forms.ModelForm):
class UserCreationForm(BaseUserCreationForm):
- error_messages = {
- **BaseUserCreationForm.error_messages,
- "unique": _("A user with that username already exists."),
- }
-
def clean_username(self):
"""Reject usernames that differ only in case."""
username = self.cleaned_data.get("username")
- if username and User.objects.filter(username__iexact=username).exists():
- raise forms.ValidationError(self.error_messages["unique"], code="unique")
+ if (
+ username
+ and self._meta.model.objects.filter(username__iexact=username).exists()
+ ):
+ self._update_errors(
+ ValidationError(
+ {
+ "username": self.instance.unique_error_message(
+ self._meta.model, ["username"]
+ )
+ }
+ )
+ )
else:
return username
diff --git a/django/contrib/auth/locale/en/LC_MESSAGES/django.po b/django/contrib/auth/locale/en/LC_MESSAGES/django.po
index bc6eff91dd..8b15915f9f 100644
--- a/django/contrib/auth/locale/en/LC_MESSAGES/django.po
+++ b/django/contrib/auth/locale/en/LC_MESSAGES/django.po
@@ -77,10 +77,6 @@ msgstr ""
msgid "Enter the same password as before, for verification."
msgstr ""
-#: contrib/auth/forms.py:152 contrib/auth/models.py:353
-msgid "A user with that username already exists."
-msgstr ""
-
#: contrib/auth/forms.py:168
msgid ""
"Raw passwords are not stored, so there is no way to see this user’s "
@@ -240,6 +236,10 @@ msgstr ""
msgid "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only."
msgstr ""
+#: contrib/auth/models.py:353
+msgid "A user with that username already exists."
+msgstr ""
+
#: contrib/auth/models.py:356
msgid "first name"
msgstr ""