show/hide button interactivity
This commit is contained in:
@ -53,6 +53,13 @@ def del_item():
|
||||
delete_item(uuid)
|
||||
return jsonify({'deleted': uuid}), 200
|
||||
|
||||
@app.route('/show', methods=['POST'])
|
||||
def toggle_item_show():
|
||||
data = request.get_json()
|
||||
uuid = data.get('uuid')
|
||||
toggle_show(uuid)
|
||||
return jsonify({'toggled show/hide ': uuid}), 200
|
||||
|
||||
@app.route('/datahistory',methods = ['GET'])
|
||||
def data_history_request():
|
||||
if request.method == 'GET':
|
||||
|
28
src/db.py
28
src/db.py
@ -27,13 +27,16 @@ def connect_db():
|
||||
return conn
|
||||
|
||||
def add_item(itemid, skuid, choice, attributes, image):
|
||||
'''insert a new item in the database'''
|
||||
'''
|
||||
insert a new item in the database
|
||||
items are shown by default
|
||||
'''
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
INSERT INTO item (uuid, itemid, skuid, choice, attributes, image)
|
||||
VALUES (nextval('uuid_sequence'), %s, %s, %s, %s, %s)
|
||||
INSERT INTO item (uuid, itemid, skuid, choice, attributes, image, show)
|
||||
VALUES (nextval('uuid_sequence'), %s, %s, %s, %s, %s, true)
|
||||
""", (itemid, skuid, choice, attributes, image))
|
||||
connection.commit()
|
||||
connection.close()
|
||||
@ -80,7 +83,7 @@ def get_item():
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
SELECT uuid, itemid, skuid, choice, attributes, image
|
||||
SELECT uuid, itemid, skuid, choice, attributes, image, show
|
||||
FROM item
|
||||
""")
|
||||
results = cursor.fetchall()
|
||||
@ -101,6 +104,22 @@ def get_item_keys():
|
||||
connection.close()
|
||||
return results
|
||||
|
||||
def toggle_show(uuid):
|
||||
'''
|
||||
show an item if hidden
|
||||
hide if shown
|
||||
'''
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
UPDATE item
|
||||
SET show = NOT show
|
||||
WHERE uuid = %s
|
||||
""", (uuid,))
|
||||
cursor.close()
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def check_exist(itemid, skuid):
|
||||
'''check if an item is already in the database'''
|
||||
connection = connect_db()
|
||||
@ -193,6 +212,7 @@ def initialize():
|
||||
choice boolean,
|
||||
attributes text[],
|
||||
image text,
|
||||
show boolean,
|
||||
primary key (uuid)
|
||||
)
|
||||
""")
|
||||
|
Reference in New Issue
Block a user