-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.py
142 lines (114 loc) · 3.88 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import random
import shelve
from Functions import*
from StorageClass import*
class User:
def __init__(self, username, password, email):
self.set_user_id()
self.set_username(username)
self.set_password(password)
self.set_email(email)
# self.set_profile_pic(r"..\static\images\default-profile-picture1.jpg")
self.__phone = ""
self.__wishlist = {}
self.__address = ""
self.__shopping_cart = {}
self.__wishlist = {}
self.__transactions = []
self.__discount_codes = []
self.__current_discount = {} #contains discount object, amt after, amt before and deducted
def set_user_id(self):
user_id = random.randint(0, 9999999999999999999999999)
db = shelve.open('storage.db')
usersDict = {}
try:
usersDict = db['Users']
except:
print("This is an error in User.py")
current = []
for user in usersDict:
id = user
current.append(id)
same = True
while same:
if user_id in current:
user_id = random.randint(0, 9999999999999999999999999)
else:
same = False
self.__user_id = str(user_id)
def set_username(self, username):
self.__username = username
def set_password(self, password):
self.__password = password
def set_profile_pic(self, pic):
self.__profile_pic = pic
def set_phone(self, phone):
self.__phone = phone
def set_wishlist(self, wishlist):
self.__wishlist = wishlist
def set_shopping_cart(self, shopping_cart):
self.__shopping_cart = shopping_cart
def set_address(self, address):
self.__address = address
def set_email(self, email):
self.__email = email
def set_transactions(self, transactions):
self.__transactions.append(transactions)
def set_discount_codes(self, discount_codes):
self.__discount_codes = discount_codes
def set_current_discount(self, current_discount):
self.__current_discount = current_discount
def get_user_id(self):
return self.__user_id
def get_username(self):
return self.__username
def get_password(self):
return self.__password
def get_phone(self):
return self.__phone
def get_wishlist(self):
return self.__wishlist
def get_shopping_cart(self):
return self.__shopping_cart
def get_address(self):
return self.__address
def get_email(self):
return self.__email
def get_transactions(self):
return self.__transactions
def get_discount_codes(self):
return self.__discount_codes
def get_current_discount(self):
return self.__current_discount
def add_to_wishlist(self, item):
wishlist = self.get_wishlist()
serial_no = item.get_serial_no()
empty = not bool(wishlist)
if empty == True:
wishlist[serial_no] = item
else:
for key in wishlist:
same = False
if key == serial_no:
same = True
break
else:
same = False
if same == False:
wishlist[serial_no] = item
self.set_wishlist(wishlist)
def remove_from_wishlist(self, item):
wishlist = self.get_wishlist()
serial_no = item.get_serial_no()
del wishlist[serial_no]
self.set_wishlist(wishlist)
def add_to_cart(self, item, quantity):
cart = self.get_shopping_cart()
serial_no = item.get_serial_no()
cart[serial_no] = quantity
self.set_shopping_cart(cart)
def remove_from_cart(self, item):
cart = self.get_shopping_cart()
serial_no = item.get_serial_no()
del cart[serial_no]
self.set_shopping_cart(cart)