]>
git.frykholm.com Git - tranquillity.git/blob - customerportal/models.py
9a36b9f3154d8924ee51d5db7b86d16671ddb1f0
1 from django
.db
import models
2 from django
.contrib
.auth
.models
import User
3 from django
.contrib
.auth
.models
import AbstractUser
4 from django
.contrib
.auth
.models
import AbstractUser
, BaseUserManager
## A new class is imported. ##
5 from django
.db
import models
6 from django
.utils
.translation
import ugettext_lazy
as _
9 class UserManager(BaseUserManager
):
10 """Define a model manager for User model with no username field."""
12 use_in_migrations
= True
14 def _create_user(self
, email
, password
, **extra_fields
):
15 """Create and save a User with the given email and password."""
17 raise ValueError('The given email must be set')
18 email
= self
.normalize_email(email
)
19 user
= self
.model(email
=email
, **extra_fields
)
20 user
.set_password(password
)
21 user
.save(using
=self
._db
)
24 def create_user(self
, email
, password
=None, **extra_fields
):
25 """Create and save a regular User with the given email and password."""
26 extra_fields
.setdefault('is_staff', False)
27 extra_fields
.setdefault('is_superuser', False)
28 return self
._create
_user
(email
, password
, **extra_fields
)
30 def create_superuser(self
, email
, password
, **extra_fields
):
31 """Create and save a SuperUser with the given email and password."""
32 extra_fields
.setdefault('is_staff', True)
33 extra_fields
.setdefault('is_superuser', True)
35 if extra_fields
.get('is_staff') is not True:
36 raise ValueError('Superuser must have is_staff=True.')
37 if extra_fields
.get('is_superuser') is not True:
38 raise ValueError('Superuser must have is_superuser=True.')
40 return self
._create
_user
(email
, password
, **extra_fields
)
43 class User(AbstractUser
):
45 fortnox_external_id
= models
.IntegerField()
46 gpg_public_key
= models
.CharField(null
=True, max_length
=4096)
47 ssh_public_key
= models
.CharField(null
=True, max_length
=4096)
48 last_login
= models
.DateField(null
=True)
49 cos_id
= models
.CharField(null
=True, max_length
=4096)
50 cos_contractid
= models
.CharField(null
=True, max_length
=4096)
51 cos_anlaggningsid
= models
.CharField(null
=True, max_length
=4096)
52 USERNAME_FIELD
= 'email'
53 REQUIRED_FIELDS
= ['fortnox_external_id']
54 objects
= UserManager() ## This is the new line in the User model. ##
56 class vps(models
.Model
):
57 user
= models
.ForeignKey(to
=User
, on_delete
=models
.CASCADE
)
58 uuid
= models
.CharField(max_length
=4096)
60 class physical_server(models
.Model
):
61 user
= models
.ForeignKey(to
=User
, on_delete
=models
.CASCADE
)
62 rack
= models
.CharField(max_length
=4096)
63 unit
= models
.IntegerField()
65 class IP(models
.Model
):
66 user
= models
.ForeignKey(to
=User
, on_delete
=models
.CASCADE
)
67 cidr
= models
.CharField(max_length
=4096)
71 # port on device (realtime) autodetect on description(Cust: fortnox_external_id)