1
|
6
|
from __future__ import unicode_literals
|
2
|
|
|
3
|
6
|
from django.db import models
|
4
|
6
|
from django.core.mail import send_mail
|
5
|
6
|
from django.contrib.auth.models import PermissionsMixin
|
6
|
6
|
from django.contrib.auth.base_user import AbstractBaseUser
|
7
|
6
|
from django.utils.translation import ugettext_lazy as _
|
8
|
|
|
9
|
6
|
from cyborgbackup.main.managers import UserManager
|
10
|
|
|
11
|
|
|
12
|
6
|
class User(AbstractBaseUser, PermissionsMixin):
|
13
|
6
|
email = models.EmailField(_('email address'), unique=True)
|
14
|
6
|
first_name = models.CharField(_('first name'), max_length=30, blank=True)
|
15
|
6
|
last_name = models.CharField(_('last name'), max_length=30, blank=True)
|
16
|
6
|
date_joined = models.DateTimeField(_('date joined'), auto_now_add=True)
|
17
|
6
|
is_active = models.BooleanField(_('active'), default=True)
|
18
|
6
|
is_agent = models.BooleanField(
|
19
|
|
default=False
|
20
|
|
)
|
21
|
6
|
notify_backup_failed = models.BooleanField(
|
22
|
|
default=False
|
23
|
|
)
|
24
|
6
|
notify_backup_success = models.BooleanField(
|
25
|
|
default=False
|
26
|
|
)
|
27
|
6
|
notify_backup_summary = models.BooleanField(
|
28
|
|
default=False
|
29
|
|
)
|
30
|
6
|
notify_backup_daily = models.BooleanField(
|
31
|
|
default=False
|
32
|
|
)
|
33
|
6
|
notify_backup_weekly = models.BooleanField(
|
34
|
|
default=False
|
35
|
|
)
|
36
|
6
|
notify_backup_monthly = models.BooleanField(
|
37
|
|
default=False
|
38
|
|
)
|
39
|
|
# avatar = models.ImageField(upload_to='avatars/', null=True, blank=True)
|
40
|
|
|
41
|
6
|
objects = UserManager()
|
42
|
|
|
43
|
6
|
USERNAME_FIELD = 'email'
|
44
|
6
|
REQUIRED_FIELDS = []
|
45
|
|
|
46
|
6
|
class Meta:
|
47
|
6
|
verbose_name = _('user')
|
48
|
6
|
verbose_name_plural = _('users')
|
49
|
|
|
50
|
6
|
def get_full_name(self):
|
51
|
|
'''
|
52
|
|
Returns the first_name plus the last_name, with a space in between.
|
53
|
|
'''
|
54
|
0
|
full_name = '%s %s' % (self.first_name, self.last_name)
|
55
|
0
|
return full_name.strip()
|
56
|
|
|
57
|
6
|
def get_short_name(self):
|
58
|
|
'''
|
59
|
|
Returns the short name for the user.
|
60
|
|
'''
|
61
|
0
|
return self.first_name
|
62
|
|
|
63
|
6
|
def email_user(self, subject, message, from_email=None, **kwargs):
|
64
|
|
'''
|
65
|
|
Sends an email to this User.
|
66
|
|
'''
|
67
|
0
|
send_mail(subject, message, from_email, [self.email], **kwargs)
|