mirror of https://github.com/django/django.git
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
This commit is contained in:
commit
a9491a8776
|
@ -29,7 +29,7 @@ class Command(BaseCommand):
|
||||||
) + tuple(
|
) + tuple(
|
||||||
make_option('--%s' % field, dest=field, default=None,
|
make_option('--%s' % field, dest=field, default=None,
|
||||||
help='Specifies the %s for the superuser.' % field)
|
help='Specifies the %s for the superuser.' % field)
|
||||||
for field in getattr(get_user_model(), 'REQUIRED_FIELDS', ['email'])
|
for field in get_user_model().REQUIRED_FIELDS
|
||||||
)
|
)
|
||||||
|
|
||||||
help = 'Used to create a superuser.'
|
help = 'Used to create a superuser.'
|
||||||
|
@ -43,7 +43,7 @@ class Command(BaseCommand):
|
||||||
UserModel = get_user_model()
|
UserModel = get_user_model()
|
||||||
|
|
||||||
username_field = UserModel._meta.get_field(getattr(UserModel, 'USERNAME_FIELD', 'username'))
|
username_field = UserModel._meta.get_field(getattr(UserModel, 'USERNAME_FIELD', 'username'))
|
||||||
other_fields = getattr(UserModel, 'REQUIRED_FIELDS', ['email'])
|
other_fields = UserModel.REQUIRED_FIELDS
|
||||||
|
|
||||||
# If not provided, create the user with an unusable password
|
# If not provided, create the user with an unusable password
|
||||||
password = None
|
password = None
|
||||||
|
|
|
@ -170,7 +170,7 @@ class BaseUserManager(models.Manager):
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
|
|
||||||
def create_user(self, username, email=None, password=None):
|
def create_user(self, username, email=None, password=None, **extra_fields):
|
||||||
"""
|
"""
|
||||||
Creates and saves a User with the given username, email and password.
|
Creates and saves a User with the given username, email and password.
|
||||||
"""
|
"""
|
||||||
|
@ -180,14 +180,14 @@ class UserManager(BaseUserManager):
|
||||||
email = UserManager.normalize_email(email)
|
email = UserManager.normalize_email(email)
|
||||||
user = self.model(username=username, email=email,
|
user = self.model(username=username, email=email,
|
||||||
is_staff=False, is_active=True, is_superuser=False,
|
is_staff=False, is_active=True, is_superuser=False,
|
||||||
last_login=now, date_joined=now)
|
last_login=now, date_joined=now, **extra_fields)
|
||||||
|
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
user.save(using=self._db)
|
user.save(using=self._db)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def create_superuser(self, username, email, password):
|
def create_superuser(self, username, email, password, **extra_fields):
|
||||||
u = self.create_user(username, email, password)
|
u = self.create_user(username, email, password, **extra_fields)
|
||||||
u.is_staff = True
|
u.is_staff = True
|
||||||
u.is_active = True
|
u.is_active = True
|
||||||
u.is_superuser = True
|
u.is_superuser = True
|
||||||
|
@ -228,6 +228,7 @@ def _user_has_module_perms(user, app_label):
|
||||||
|
|
||||||
|
|
||||||
class AbstractBaseUser(models.Model):
|
class AbstractBaseUser(models.Model):
|
||||||
|
REQUIRED_FIELDS = []
|
||||||
password = models.CharField(_('password'), max_length=128)
|
password = models.CharField(_('password'), max_length=128)
|
||||||
last_login = models.DateTimeField(_('last login'), default=timezone.now)
|
last_login = models.DateTimeField(_('last login'), default=timezone.now)
|
||||||
|
|
||||||
|
@ -276,13 +277,14 @@ class AbstractBaseUser(models.Model):
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class User(AbstractBaseUser):
|
class AbstractUser(AbstractBaseUser):
|
||||||
"""
|
"""
|
||||||
Users within the Django authentication system are represented by this
|
Users within the Django authentication system are represented by this
|
||||||
model.
|
model.
|
||||||
|
|
||||||
Username and password are required. Other fields are optional.
|
Username and password are required. Other fields are optional.
|
||||||
"""
|
"""
|
||||||
|
REQUIRED_FIELDS = ['email']
|
||||||
username = models.CharField(_('username'), max_length=30, unique=True,
|
username = models.CharField(_('username'), max_length=30, unique=True,
|
||||||
help_text=_('Required. 30 characters or fewer. Letters, numbers and '
|
help_text=_('Required. 30 characters or fewer. Letters, numbers and '
|
||||||
'@/./+/-/_ characters'),
|
'@/./+/-/_ characters'),
|
||||||
|
@ -315,7 +317,7 @@ class User(AbstractBaseUser):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('user')
|
verbose_name = _('user')
|
||||||
verbose_name_plural = _('users')
|
verbose_name_plural = _('users')
|
||||||
swappable = 'AUTH_USER_MODEL'
|
abstract = True
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.username
|
return self.username
|
||||||
|
@ -432,6 +434,9 @@ class User(AbstractBaseUser):
|
||||||
raise SiteProfileNotAvailable
|
raise SiteProfileNotAvailable
|
||||||
return self._profile_cache
|
return self._profile_cache
|
||||||
|
|
||||||
|
class User(AbstractUser):
|
||||||
|
class Meta:
|
||||||
|
swappable = 'AUTH_USER_MODEL'
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class AnonymousUser(object):
|
class AnonymousUser(object):
|
||||||
|
|
Loading…
Reference in New Issue