From 8e7cb95012c0191ea916eeaa54303be38f431859 Mon Sep 17 00:00:00 2001 From: Victor Munene Date: Tue, 25 Mar 2014 02:43:29 +0300 Subject: [PATCH] Patched the migrations and wagtailusers app to add better support for custom AUTH_USER_MODEL --- wagtail/wagtailcore/compat.py | 11 ++++++++++ .../wagtailcore/migrations/0001_initial.py | 14 +++++++------ .../migrations/0002_initial_data.py | 11 ++++++---- .../wagtaildocs/migrations/0001_initial.py | 10 ++++++---- .../migrations/0002_initial_data.py | 9 ++++++--- .../wagtailimages/migrations/0001_initial.py | 10 ++++++---- .../migrations/0002_initial_data.py | 9 ++++++--- .../wagtailsearch/migrations/0001_initial.py | 8 +++++--- .../0002_auto__add_field_searchtest_live.py | 8 +++++--- wagtail/wagtailusers/forms.py | 20 ++++++++++++++++++- wagtail/wagtailusers/views/users.py | 10 +++++++--- 11 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 wagtail/wagtailcore/compat.py diff --git a/wagtail/wagtailcore/compat.py b/wagtail/wagtailcore/compat.py new file mode 100644 index 000000000..71fbc39ac --- /dev/null +++ b/wagtail/wagtailcore/compat.py @@ -0,0 +1,11 @@ +from django.conf import settings + +# A setting that can be used in foreign key declarations +AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') +# Two additional settings that are useful in South migrations when +# specifying the user model in the FakeORM +try: + AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME = AUTH_USER_MODEL.rsplit('.', 1) +except ValueError: + raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form" + " 'app_label.model_name'") \ No newline at end of file diff --git a/wagtail/wagtailcore/migrations/0001_initial.py b/wagtail/wagtailcore/migrations/0001_initial.py index bac5fa314..954bc38c5 100644 --- a/wagtail/wagtailcore/migrations/0001_initial.py +++ b/wagtail/wagtailcore/migrations/0001_initial.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + class Migration(SchemaMigration): @@ -30,7 +32,7 @@ class Migration(SchemaMigration): ('live', self.gf('django.db.models.fields.BooleanField')(default=True)), ('has_unpublished_changes', self.gf('django.db.models.fields.BooleanField')(default=False)), ('url_path', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)), - ('owner', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='owned_pages', null=True, to=orm['auth.User'])), + ('owner', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='owned_pages', null=True, to=orm[AUTH_USER_MODEL])), ('seo_title', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)), ('show_in_menus', self.gf('django.db.models.fields.BooleanField')(default=False)), ('search_description', self.gf('django.db.models.fields.TextField')(blank=True)), @@ -43,7 +45,7 @@ class Migration(SchemaMigration): ('page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='revisions', to=orm['wagtailcore.Page'])), ('submitted_for_moderation', self.gf('django.db.models.fields.BooleanField')(default=False)), ('created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), - ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True)), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm[AUTH_USER_MODEL], null=True, blank=True)), ('content_json', self.gf('django.db.models.fields.TextField')()), )) db.send_create_signal(u'wagtailcore', ['PageRevision']) @@ -86,8 +88,8 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -124,7 +126,7 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'live': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'numchild': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), - 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['auth.User']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['%s']" % AUTH_USER_MODEL}), 'path': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), 'search_description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), 'seo_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), @@ -140,7 +142,7 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'revisions'", 'to': u"orm['wagtailcore.Page']"}), 'submitted_for_moderation': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}) + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['%s']" % AUTH_USER_MODEL, 'null': 'True', 'blank': 'True'}) }, u'wagtailcore.site': { 'Meta': {'object_name': 'Site'}, diff --git a/wagtail/wagtailcore/migrations/0002_initial_data.py b/wagtail/wagtailcore/migrations/0002_initial_data.py index 7445d746e..668f554bd 100644 --- a/wagtail/wagtailcore/migrations/0002_initial_data.py +++ b/wagtail/wagtailcore/migrations/0002_initial_data.py @@ -5,6 +5,9 @@ from south.v2 import DataMigration from django.db import models, connection from django.db.transaction import set_autocommit +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + + class Migration(DataMigration): def forwards(self, orm): @@ -71,8 +74,8 @@ class Migration(DataMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -109,7 +112,7 @@ class Migration(DataMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'live': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'numchild': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), - 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['auth.User']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['%s']" % AUTH_USER_MODEL}), 'path': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), 'search_description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), 'seo_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), @@ -125,7 +128,7 @@ class Migration(DataMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'revisions'", 'to': u"orm['wagtailcore.Page']"}), 'submitted_for_moderation': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}) + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['%s']" % AUTH_USER_MODEL, 'null': 'True', 'blank': 'True'}) }, u'wagtailcore.site': { 'Meta': {'object_name': 'Site'}, diff --git a/wagtail/wagtaildocs/migrations/0001_initial.py b/wagtail/wagtaildocs/migrations/0001_initial.py index 569a200c7..fb3805eb5 100644 --- a/wagtail/wagtaildocs/migrations/0001_initial.py +++ b/wagtail/wagtaildocs/migrations/0001_initial.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + class Migration(SchemaMigration): @@ -20,7 +22,7 @@ class Migration(SchemaMigration): ('created_at', self.gf('django.db.models.fields.DateTimeField') (auto_now_add=True, blank=True)), ('uploaded_by_user', self.gf('django.db.models.fields.related.ForeignKey') - (to=orm['auth.User'], null=True, blank=True)), + (to=orm[AUTH_USER_MODEL], null=True, blank=True)), )) db.send_create_signal(u'wagtaildocs', ['Document']) @@ -42,8 +44,8 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -71,7 +73,7 @@ class Migration(SchemaMigration): 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}) + 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['%s']" % AUTH_USER_MODEL, 'null': 'True', 'blank': 'True'}) } } diff --git a/wagtail/wagtaildocs/migrations/0002_initial_data.py b/wagtail/wagtaildocs/migrations/0002_initial_data.py index 3c21f5b92..a23f79c88 100644 --- a/wagtail/wagtaildocs/migrations/0002_initial_data.py +++ b/wagtail/wagtaildocs/migrations/0002_initial_data.py @@ -5,6 +5,9 @@ from south.v2 import DataMigration from django.db import models, connection from django.db.transaction import set_autocommit +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + + class Migration(DataMigration): def forwards(self, orm): @@ -50,8 +53,8 @@ class Migration(DataMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -79,7 +82,7 @@ class Migration(DataMigration): 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}) + 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['%s']" % AUTH_USER_MODEL, 'null': 'True', 'blank': 'True'}) } } diff --git a/wagtail/wagtailimages/migrations/0001_initial.py b/wagtail/wagtailimages/migrations/0001_initial.py index cf502fc69..aebf9c992 100644 --- a/wagtail/wagtailimages/migrations/0001_initial.py +++ b/wagtail/wagtailimages/migrations/0001_initial.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + class Migration(SchemaMigration): @@ -22,7 +24,7 @@ class Migration(SchemaMigration): ('created_at', self.gf('django.db.models.fields.DateTimeField') (auto_now_add=True, blank=True)), ('uploaded_by_user', self.gf('django.db.models.fields.related.ForeignKey') - (to=orm['auth.User'], null=True, blank=True)), + (to=orm[AUTH_USER_MODEL], null=True, blank=True)), )) db.send_create_signal(u'wagtailimages', ['Image']) @@ -77,8 +79,8 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -112,7 +114,7 @@ class Migration(SchemaMigration): 'height': ('django.db.models.fields.IntegerField', [], {}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}), + 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['%s']" % AUTH_USER_MODEL, 'null': 'True', 'blank': 'True'}), 'width': ('django.db.models.fields.IntegerField', [], {}) }, u'wagtailimages.rendition': { diff --git a/wagtail/wagtailimages/migrations/0002_initial_data.py b/wagtail/wagtailimages/migrations/0002_initial_data.py index 21ac3b5b3..82731f93b 100644 --- a/wagtail/wagtailimages/migrations/0002_initial_data.py +++ b/wagtail/wagtailimages/migrations/0002_initial_data.py @@ -5,6 +5,9 @@ from south.v2 import DataMigration from django.db import models, connection from django.db.transaction import set_autocommit +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + + class Migration(DataMigration): def forwards(self, orm): @@ -50,8 +53,8 @@ class Migration(DataMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -85,7 +88,7 @@ class Migration(DataMigration): 'height': ('django.db.models.fields.IntegerField', [], {}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}), + 'uploaded_by_user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['%s']" % AUTH_USER_MODEL, 'null': 'True', 'blank': 'True'}), 'width': ('django.db.models.fields.IntegerField', [], {}) }, u'wagtailimages.rendition': { diff --git a/wagtail/wagtailsearch/migrations/0001_initial.py b/wagtail/wagtailsearch/migrations/0001_initial.py index 1eaacd6b6..45aa27cd2 100644 --- a/wagtail/wagtailsearch/migrations/0001_initial.py +++ b/wagtail/wagtailsearch/migrations/0001_initial.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + class Migration(SchemaMigration): @@ -98,8 +100,8 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -129,7 +131,7 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'live': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'numchild': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), - 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['auth.User']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['%s']" % AUTH_USER_MODEL}), 'path': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), 'search_description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), 'seo_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), diff --git a/wagtail/wagtailsearch/migrations/0002_auto__add_field_searchtest_live.py b/wagtail/wagtailsearch/migrations/0002_auto__add_field_searchtest_live.py index dd075efcb..b21c83b8b 100644 --- a/wagtail/wagtailsearch/migrations/0002_auto__add_field_searchtest_live.py +++ b/wagtail/wagtailsearch/migrations/0002_auto__add_field_searchtest_live.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from wagtail.wagtailcore.compat import AUTH_USER_MODEL, AUTH_USER_MODEL_NAME + class Migration(SchemaMigration): @@ -33,8 +35,8 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, - u'auth.user': { - 'Meta': {'object_name': 'User'}, + AUTH_USER_MODEL: { + 'Meta': {'object_name': AUTH_USER_MODEL_NAME}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), @@ -64,7 +66,7 @@ class Migration(SchemaMigration): u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'live': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'numchild': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), - 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['auth.User']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_pages'", 'null': 'True', 'to': u"orm['%s']" % AUTH_USER_MODEL}), 'path': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), 'search_description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), 'seo_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), diff --git a/wagtail/wagtailusers/forms.py b/wagtail/wagtailusers/forms.py index b7229194d..1624c65ce 100644 --- a/wagtail/wagtailusers/forms.py +++ b/wagtail/wagtailusers/forms.py @@ -1,8 +1,10 @@ from django import forms -from django.contrib.auth.models import User +from django.contrib.auth import get_user_model from django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm from django.utils.translation import ugettext_lazy as _ +User = get_user_model() + # extend Django's UserCreationForm with an 'is_superuser' field class UserCreationForm(BaseUserCreationForm): @@ -25,6 +27,22 @@ class UserCreationForm(BaseUserCreationForm): 'groups': forms.CheckboxSelectMultiple } + def clean_username(self): + # Method copied from parent + + username = self.cleaned_data["username"] + try: + # When called from BaseUserCreationForm, the method fails if using a AUTH_MODEL_MODEL, + # This is because the following line tries to perform a lookup on + # the default "auth_user" table. + User._default_manager.get(username=username) + except User.DoesNotExist: + return username + raise forms.ValidationError( + self.error_messages['duplicate_username'], + code='duplicate_username', + ) + def save(self, commit=True): user = super(UserCreationForm, self).save(commit=False) diff --git a/wagtail/wagtailusers/views/users.py b/wagtail/wagtailusers/views/users.py index 08cc41fa7..c8706d663 100644 --- a/wagtail/wagtailusers/views/users.py +++ b/wagtail/wagtailusers/views/users.py @@ -8,10 +8,14 @@ from django.utils.translation import ugettext as _ from wagtail.wagtailadmin.forms import SearchForm from wagtail.wagtailusers.forms import UserCreationForm, UserEditForm +from wagtail.wagtailcore.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME User = get_user_model() -@permission_required('auth.change_user') +change_user_perm = "{0}.change_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower()) + + +@permission_required(change_user_perm) def index(request): q = None p = request.GET.get("p", 1) @@ -66,7 +70,7 @@ def index(request): 'query_string': q, }) -@permission_required('auth.change_user') +@permission_required(change_user_perm) def create(request): if request.POST: form = UserCreationForm(request.POST) @@ -84,7 +88,7 @@ def create(request): }) -@permission_required('auth.change_user') +@permission_required(change_user_perm) def edit(request, user_id): user = get_object_or_404(User, id=user_id) if request.POST: