From 04dcc6984ce8077fd9071aa3562f2676d9270a49 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 4 Sep 2015 14:19:11 +0100 Subject: [PATCH 1/3] Add error_messages attribute to UserCreationForm Fixes #1665 --- wagtail/wagtailusers/forms.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailusers/forms.py b/wagtail/wagtailusers/forms.py index ce4108a01..fa1736068 100644 --- a/wagtail/wagtailusers/forms.py +++ b/wagtail/wagtailusers/forms.py @@ -43,8 +43,13 @@ class UsernameForm(forms.ModelForm): class UserCreationForm(UsernameForm): - required_css_class = "required" + + error_messages = { + 'duplicate_username': _("A user with that username already exists."), + 'password_mismatch': _("The two password fields didn't match."), + } + is_superuser = forms.BooleanField( label=_("Administrator"), required=False, From 07e37af3eb2a8abcfe9183d2dfd5fe23a92d67e6 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 4 Sep 2015 14:48:51 +0100 Subject: [PATCH 2/3] Assert that an error message is present --- wagtail/wagtailusers/tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wagtail/wagtailusers/tests.py b/wagtail/wagtailusers/tests.py index 5d5971225..915a3789b 100644 --- a/wagtail/wagtailusers/tests.py +++ b/wagtail/wagtailusers/tests.py @@ -96,6 +96,8 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'wagtailusers/users/create.html') + self.assertTrue(response.context['form'].errors['password2']) + # Check that the user was not created users = get_user_model().objects.filter(username='testuser') self.assertEqual(users.count(), 0) From 5ecc69c7a06877b90b2c325251c96fb78cab0ba6 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 4 Sep 2015 14:50:04 +0100 Subject: [PATCH 3/3] Release note for #1666 --- CHANGELOG.txt | 1 + docs/releases/1.1.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 45e03bc5b..81ed81014 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -46,6 +46,7 @@ Changelog * Fix: Form builder pages now pick up template variables defined in the `get_context` method (Christoph Lipp) * Fix: When copying a page, IDs of child objects within page revision records were not remapped to the new objects; this would cause those objects to be lost from the original page when editing the new one * Fix: Newly added redirects now take effect on all sites, rather than just the site that the Wagtail admin backend was accessed through + * Fix: Add user form no longer throws a hard error on validation failure 1.0 (16.07.2015) diff --git a/docs/releases/1.1.rst b/docs/releases/1.1.rst index b17fa5373..628421814 100644 --- a/docs/releases/1.1.rst +++ b/docs/releases/1.1.rst @@ -87,6 +87,7 @@ Bug fixes * Form builder pages now pick up template variables defined in the ``get_context`` method * When copying a page, IDs of child objects within page revision records were not remapped to the new objects; this would cause those objects to be lost from the original page when editing the new one * Newly added redirects now take effect on all sites, rather than just the site that the Wagtail admin backend was accessed through + * Add user form no longer throws a hard error on validation failure Upgrade considerations