mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Moved custom user model into its own app
This commit is contained in:
parent
682232ca5b
commit
83c7e242df
0
wagtail/tests/customuser/__init__.py
Normal file
0
wagtail/tests/customuser/__init__.py
Normal file
36
wagtail/tests/customuser/migrations/0001_initial.py
Normal file
36
wagtail/tests/customuser/migrations/0001_initial.py
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CustomUser',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(unique=True, max_length=100)),
|
||||
('email', models.EmailField(max_length=255, blank=True)),
|
||||
('is_staff', models.BooleanField(default=True)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('first_name', models.CharField(max_length=50, blank=True)),
|
||||
('last_name', models.CharField(max_length=50, blank=True)),
|
||||
('groups', models.ManyToManyField(to='auth.Group', verbose_name='groups', blank=True)),
|
||||
('user_permissions', models.ManyToManyField(to='auth.Permission', verbose_name='user permissions', blank=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('customuser', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='groups',
|
||||
field=models.ManyToManyField(to='auth.Group', verbose_name='groups', help_text='The groups this user belongs to. A user will get all permissions granted to each of his/her group.', related_name='user_set', blank=True, related_query_name='user'),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='user_permissions',
|
||||
field=models.ManyToManyField(to='auth.Permission', verbose_name='user permissions', help_text='Specific permissions for this user.', related_name='user_set', blank=True, related_query_name='user'),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
0
wagtail/tests/customuser/migrations/__init__.py
Normal file
0
wagtail/tests/customuser/migrations/__init__.py
Normal file
47
wagtail/tests/customuser/models.py
Normal file
47
wagtail/tests/customuser/models.py
Normal file
@ -0,0 +1,47 @@
|
||||
from django.db import models
|
||||
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
def _create_user(self, username, email, password,
|
||||
is_staff, is_superuser, **extra_fields):
|
||||
"""
|
||||
Creates and saves a User with the given username, email and password.
|
||||
"""
|
||||
if not username:
|
||||
raise ValueError('The given username must be set')
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(username=username, email=email,
|
||||
is_staff=is_staff, is_active=True,
|
||||
is_superuser=is_superuser, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_user(self, username, email=None, password=None, **extra_fields):
|
||||
return self._create_user(username, email, password, False, False,
|
||||
**extra_fields)
|
||||
|
||||
def create_superuser(self, username, email, password, **extra_fields):
|
||||
return self._create_user(username, email, password, True, True,
|
||||
**extra_fields)
|
||||
|
||||
|
||||
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
username = models.CharField(max_length=100, unique=True)
|
||||
email = models.EmailField(max_length=255, blank=True)
|
||||
is_staff = models.BooleanField(default=True)
|
||||
is_active = models.BooleanField(default=True)
|
||||
first_name = models.CharField(max_length=50, blank=True)
|
||||
last_name = models.CharField(max_length=50, blank=True)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
def get_full_name(self):
|
||||
return self.first_name + ' ' + self.last_name
|
||||
|
||||
def get_short_name(self):
|
||||
return self.first_name
|
@ -77,6 +77,7 @@ INSTALLED_APPS = (
|
||||
'wagtail.contrib.wagtailroutablepage',
|
||||
'wagtail.contrib.wagtailfrontendcache',
|
||||
'wagtail.tests.testapp',
|
||||
'wagtail.tests.customuser',
|
||||
|
||||
# Install wagtailredirects with its appconfig
|
||||
# Theres nothing special about wagtailredirects, we just need to have one
|
||||
@ -110,7 +111,7 @@ WAGTAILSEARCH_BACKENDS = {
|
||||
}
|
||||
}
|
||||
|
||||
AUTH_USER_MODEL = 'tests.CustomUser'
|
||||
AUTH_USER_MODEL = 'customuser.CustomUser'
|
||||
|
||||
try:
|
||||
# Only add Elasticsearch backend if the elasticsearch-py library is installed
|
||||
|
@ -461,7 +461,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "tests.customuser",
|
||||
"model": "customuser.customuser",
|
||||
"fields": {
|
||||
"username": "superuser",
|
||||
"first_name": "",
|
||||
@ -478,7 +478,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "tests.customuser",
|
||||
"model": "customuser.customuser",
|
||||
"fields": {
|
||||
"username": "eventeditor",
|
||||
"first_name": "",
|
||||
@ -496,7 +496,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 3,
|
||||
"model": "tests.customuser",
|
||||
"model": "customuser.customuser",
|
||||
"fields": {
|
||||
"username": "eventmoderator",
|
||||
"first_name": "",
|
||||
@ -514,7 +514,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 4,
|
||||
"model": "tests.customuser",
|
||||
"model": "customuser.customuser",
|
||||
"fields": {
|
||||
"username": "inactiveuser",
|
||||
"first_name": "",
|
||||
@ -532,7 +532,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 5,
|
||||
"model": "tests.customuser",
|
||||
"model": "customuser.customuser",
|
||||
"fields": {
|
||||
"username": "siteeditor",
|
||||
"first_name": "",
|
||||
@ -550,7 +550,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 6,
|
||||
"model": "tests.customuser",
|
||||
"model": "customuser.customuser",
|
||||
"fields": {
|
||||
"username": "admin_only_user",
|
||||
"first_name": "",
|
||||
|
25
wagtail/tests/testapp/migrations/0011_auto_20150330_0653.py
Normal file
25
wagtail/tests/testapp/migrations/0011_auto_20150330_0653.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tests', '0010_customimagewithadminformfields_customimagewithoutadminformfields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='customuser',
|
||||
name='groups',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='customuser',
|
||||
name='user_permissions',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='CustomUser',
|
||||
),
|
||||
]
|
@ -2,7 +2,6 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.conf.urls import url
|
||||
from django.http import HttpResponse
|
||||
@ -39,50 +38,6 @@ COMMON_PANELS = (
|
||||
)
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
def _create_user(self, username, email, password,
|
||||
is_staff, is_superuser, **extra_fields):
|
||||
"""
|
||||
Creates and saves a User with the given username, email and password.
|
||||
"""
|
||||
if not username:
|
||||
raise ValueError('The given username must be set')
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(username=username, email=email,
|
||||
is_staff=is_staff, is_active=True,
|
||||
is_superuser=is_superuser, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_user(self, username, email=None, password=None, **extra_fields):
|
||||
return self._create_user(username, email, password, False, False,
|
||||
**extra_fields)
|
||||
|
||||
def create_superuser(self, username, email, password, **extra_fields):
|
||||
return self._create_user(username, email, password, True, True,
|
||||
**extra_fields)
|
||||
|
||||
|
||||
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
username = models.CharField(max_length=100, unique=True)
|
||||
email = models.EmailField(max_length=255, blank=True)
|
||||
is_staff = models.BooleanField(default=True)
|
||||
is_active = models.BooleanField(default=True)
|
||||
first_name = models.CharField(max_length=50, blank=True)
|
||||
last_name = models.CharField(max_length=50, blank=True)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
def get_full_name(self):
|
||||
return self.first_name + ' ' + self.last_name
|
||||
|
||||
def get_short_name(self):
|
||||
return self.first_name
|
||||
|
||||
|
||||
# Link fields
|
||||
|
||||
class LinkFields(models.Model):
|
||||
|
Loading…
Reference in New Issue
Block a user