3 from django.db import models
4 from core.models import PlCoreBase
5 from core.models import Site
6 from django.contrib.auth.models import User, AbstractBaseUser, UserManager, BaseUserManager
8 # Create your models here.
10 class PLUserManager(BaseUserManager):
11 def create_user(self, email, firstname, lastname, password=None):
13 Creates and saves a User with the given email, date of
17 raise ValueError('Users must have an email address')
20 email=PLUserManager.normalize_email(email),
25 user.set_password(password)
27 user.save(using=self._db)
30 def create_superuser(self, email, firstname, lastname, password):
32 Creates and saves a superuser with the given email, date of
35 user = self.create_user(email,
41 user.save(using=self._db)
45 class PLUser(AbstractBaseUser):
50 email = models.EmailField(
51 verbose_name='email address',
58 firstname = models.CharField(help_text="person's given name", max_length=200)
59 lastname = models.CharField(help_text="person's surname", max_length=200)
61 phone = models.CharField(null=True, blank=True, help_text="phone number contact", max_length=100)
62 user_url = models.URLField(null=True, blank=True)
63 site = models.ForeignKey(Site, related_name='users', verbose_name="Site this user will be homed too", null=True)
65 is_active = models.BooleanField(default=True)
66 is_admin = models.BooleanField(default=True)
67 is_staff = models.BooleanField(default=True)
69 objects = PLUserManager()
71 USERNAME_FIELD = 'email'
72 REQUIRED_FIELDS = ['firstname', 'lastname']
74 def get_full_name(self):
75 # The user is identified by their email address
78 def get_short_name(self):
79 # The user is identified by their email address
82 def __unicode__(self):
85 def has_perm(self, perm, obj=None):
86 "Does the user have a specific permission?"
87 # Simplest possible answer: Yes, always
90 def has_module_perms(self, app_label):
91 "Does the user have permissions to view the app `app_label`?"
92 # Simplest possible answer: Yes, always
97 "Is the user a member of staff?"
98 # Simplest possible answer: All admins are staff