mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Moved non-documented auth test models to the new test location.
This commit is contained in:
43
tests/auth_tests/models/custom_permissions.py
Normal file
43
tests/auth_tests/models/custom_permissions.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
The CustomPermissionsUser users email as the identifier, but uses the normal
|
||||
Django permissions model. This allows us to check that the PermissionsMixin
|
||||
includes everything that is needed to interact with the ModelBackend.
|
||||
"""
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
||||
from django.contrib.auth.tests.custom_user import (
|
||||
CustomUserManager, RemoveGroupsAndPermissions,
|
||||
)
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
class CustomPermissionsUserManager(CustomUserManager):
|
||||
def create_superuser(self, email, password, date_of_birth):
|
||||
u = self.create_user(email, password=password, date_of_birth=date_of_birth)
|
||||
u.is_superuser = True
|
||||
u.save(using=self._db)
|
||||
return u
|
||||
|
||||
|
||||
with RemoveGroupsAndPermissions():
|
||||
@python_2_unicode_compatible
|
||||
class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin):
|
||||
email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
|
||||
date_of_birth = models.DateField()
|
||||
|
||||
custom_objects = CustomPermissionsUserManager()
|
||||
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = ['date_of_birth']
|
||||
|
||||
class Meta:
|
||||
app_label = 'auth'
|
||||
|
||||
def get_full_name(self):
|
||||
return self.email
|
||||
|
||||
def get_short_name(self):
|
||||
return self.email
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
Reference in New Issue
Block a user