-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate.py
More file actions
68 lines (59 loc) · 2.15 KB
/
Update.py
File metadata and controls
68 lines (59 loc) · 2.15 KB
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
from flask import render_template, request,session,redirect,url_for
class ClassUpdate:
def __init__(self,mysql):
self.mysql=mysql
def class_info(self):
try:
user_name=session['username']
except:
return redirect(url_for('login'))
conn = self.mysql.connect()
cursor = conn.cursor()
cursor.execute(
"SELECT * from product")
data = cursor.fetchall()
return render_template('product.html', data=data)
def class_delete(self):
name = request.args["name"]
print(name)
conn = self.mysql.connect()
cursor = conn.cursor()
try:
cursor.execute("""DELETE FROM product
WHERE id = %s"""
, (name,))
conn.commit()
return "Success"
except Exception as e:
return "Error"
def class_update(self):
id = request.args['id']
new_name = request.args['new_name']
price = request.args['price']
quantity = request.args['quantity']
vendor = request.args['vendor']
conn = self.mysql.connect()
cursor = conn.cursor()
print(id + " " + new_name + " " + price+" "+quantity+" "+vendor)
try:
cursor.execute("UPDATE product SET name=%s,unit_price=%s,quantity=%s,vendor=%s WHERE id=%s",
(new_name,price, quantity,vendor,id))
conn.commit()
except Exception as e:
return "error"
return "success"
def class_insert(self):
new_name = request.args['new_name']
price = request.args['price']
quantity = request.args['quantity']
vendor = request.args['vendor']
conn = self.mysql.connect()
cursor = conn.cursor()
try:
# TODO: dept name should be replaced by sessions dept name
cursor.execute("INSERT INTO product (name,unit_price,quantity,vendor) VALUES (%s,%s,%s,%s)",
(new_name,price,quantity,vendor,))
conn.commit()
except Exception as e:
return "error"
return "success"