-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
41 lines (30 loc) · 1.16 KB
/
models.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
from core.model import Model
class User(Model):
store = []
def validate_username(self, username: str) -> None:
assert isinstance(username, str) and len(username) >= 4, "Username must be str type and length >= 4"
for user in self.__class__.store:
if hasattr(user, "username"):
assert user.username != username, "Username already exists !"
@staticmethod
def validate_password(password: str) -> None:
assert isinstance(password, str) and len(password) >= 4, "Password must be str type and length >= 4"
def __init__(self, username: str, password: str) -> None:
self.username = username
self.password = password
@property
def username(self) -> str:
return self.__username
@username.setter
def username(self, new_username: str) -> None:
self.validate_username(new_username)
self.__username = new_username
@property
def password(self) -> str:
return self.__password
@password.setter
def password(self, new_password: str) -> None:
self.validate_password(new_password)
self.__password = new_password
class Drug:
pass