-
Notifications
You must be signed in to change notification settings - Fork 2
/
superuser.py
165 lines (124 loc) · 4.45 KB
/
superuser.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import sqlite3
from customer import Customer
from payment_option import PaymentOption
import os
class Superuser():
'''
Purpose:
This class handles the superusers actions
Methods:
register_customer(self,customer)
user_is_registered(self,customer)
activate_customer(self,customer)
user_is_active(self,customer)
add_product_to_order(self,order,product)
Author:
@rtwhitfield84
'''
def add_product_to_order(self, product, order, id):
order.add_product(product, id)
def get_last_order_id(self):
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
SELECT idOrder MAX
FROM Orders
"""
try:
cursor.execute(sql_command)
except:
print("ERROR GETTING MAX ORDERID")
last_order = cursor.fetchall()
return len(last_order)
connection.commit()
connection.close()
def get_all_products(self):
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
SELECT *
FROM Products
"""
try:
cursor.execute(sql_command)
except:
print("************ERROR GETTING ALL PRODUCTS**************")
return cursor.fetchall()
connection.commit()
connection.close()
def register_payment_option(self, payment_option):
payment_option.save_to_db()
def register_customer(self,customer):
Customer.register_customer_in_db(self,customer)
def customer_is_registered(self,customer):
Customer.customer_is_registered(customer)
def activate_customer(self,customer):
pass
def customer_is_active(self,customer):
return True
def get_customer_by_id(self,id):
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
SELECT *
FROM Customers
WHERE idCustomer={}
""".format(id)
try:
cursor.execute(sql_command)
except:
print("************ERROR GETTING CUSTOMER**************")
results = cursor.fetchall()[0]
new_customer = Customer(object,results[1],results[2],results[3],results[4],results[5],results[6],results[7],results[8], results[9])
return new_customer
connection.commit()
connection.close()
def get_all_customer_payments(self, customer_id):
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
SELECT *
FROM Payments
WHERE idCustomer={}
""".format(customer_id)
try:
cursor.execute(sql_command)
except:
print("************ERROR GETTING ALL PRODUCTS**************")
results = cursor.fetchall()
connection.commit()
connection.close()
return results
def get_payment_option_by_id(self,id, customer_id):
print("(*@&#$*(&@#*$&(*@#&$*(@&#*($&@#(*$&(@*#&$*")
print(self, id, customer_id)
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
SELECT *
FROM Payments
WHERE idPayment={}
""".format(id)
try:
cursor.execute(sql_command)
except:
print("************ERROR GETTING PAYMENT OPTION**************")
results = cursor.fetchall()[0]
new_payment = PaymentOption(object,results[1],results[2],results[3],results[4],results[5], customer_id)
return new_payment
connection.commit()
connection.close()
def get_dir_fix(self):
if os.path.basename(os.getcwd()) == 'tests' or os.path.basename(os.getcwd()) == 'scripts':
return '../'
else:
return ''
def get_customers():
with sqlite3.connect("../bangazon.db") as b:
cursor = b.cursor()
try:
cursor.execute("SELECT c.idCustomer,c.first_name, c.last_name, c.password FROM Customers c")
except sqlite3.OperationalError:
return False
customer = cursor.fetchall()
return customer