-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
77 lines (62 loc) · 1.92 KB
/
user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from datetime import datetime
import uuid
# User class
class User():
def __init__(self, title,blood, first_name, last_name, email,address,contacts, id="", verified=False):
# Main initialiser
self.title = title if title != "none" else ""
self.blood = blood
self.first_name = first_name
self.last_name = last_name
self.email = email
self.address = address
self.contacts = contacts
self.id = uuid.uuid4().hex if not id else id
self.verified = verified
@classmethod
def make_from_dict(cls, d):
# Initialise User object from a dictionary
return cls(d['title'],d['blood'], d['first_name'], d['last_name'], d['email'],d['address'],d['contacts'], d['id'], d['verified'])
def dict(self):
# Return dictionary representation of the object
return {
"id": self.id,
"title": self.title,
"blood": self.blood,
"first_name": self.first_name,
"last_name": self.last_name,
"email": self.email,
"address":self.address,
"contacts":self.contacts,
"verified": self.verified
}
def display_name(self):
# Return concatenation of name components
if self.title:
return self.title + " " + self.first_name + " " + self.last_name
else:
return self.first_name + " " + self.last_name
@property
def is_authenticated(self):
return True
@property
def is_active(self):
return True
@property
def is_anonymous(self):
return False
def get_id(self):
return self.id
# Anonymous user class
class Anonymous():
@property
def is_authenticated(self):
return False
@property
def is_active(self):
return False
@property
def is_anonymous(self):
return True
def get_id(self):
return None