modify itemlist interactivity
This commit is contained in:
46
src/app.py
46
src/app.py
@@ -108,6 +108,44 @@ def deleteList():
|
||||
except:
|
||||
return str('item not found in list'), 400
|
||||
|
||||
@app.route('/app/change-list-name', methods=['POST'])
|
||||
def changeListName():
|
||||
data = request.get_json()
|
||||
name = data.get('name')
|
||||
uuid = data.get('uuid')
|
||||
try:
|
||||
change_list_name(uuid, name)
|
||||
return jsonify({'name changed': uuid}), 200
|
||||
except:
|
||||
return str('error changing name'), 400
|
||||
|
||||
@app.route('/app/change-list-description', methods=['POST'])
|
||||
def changeListDescription():
|
||||
data = request.get_json()
|
||||
description = data.get('description')
|
||||
uuid = data.get('uuid')
|
||||
try:
|
||||
change_list_description(uuid, description)
|
||||
return jsonify({'name changed': uuid}), 200
|
||||
except:
|
||||
return str('error changing description'), 400
|
||||
|
||||
@app.route('/app/change-list-content', methods=['POST'])
|
||||
def changeListContent():
|
||||
data = request.get_json()
|
||||
uuid = data.get('uuid')
|
||||
new = data.get('content')
|
||||
try:
|
||||
remove_all_from_list(uuid)
|
||||
if len(new)>0 :
|
||||
for item in new.split('#'):
|
||||
add_to_list(uuid, item)
|
||||
return jsonify({'content changed': uuid}), 200
|
||||
except:
|
||||
return str('error changing content'), 400
|
||||
|
||||
|
||||
|
||||
@app.route('/app/datahistory',methods = ['GET'])
|
||||
def data_history_request():
|
||||
if request.method == 'GET':
|
||||
@@ -142,11 +180,17 @@ def data_history_request_filtered():
|
||||
lists_uuid = []
|
||||
return jsonify(get_history_filtered(lists_uuid))
|
||||
|
||||
@app.route('/app/datalist',methods = ['GET'])
|
||||
@app.route('/app/datalist',methods = ['GET', 'POST'])
|
||||
def data_list_request():
|
||||
if request.method == 'GET':
|
||||
print("fetching data item")
|
||||
return jsonify(get_lists())
|
||||
elif request.method == 'POST':
|
||||
data = request.get_json()
|
||||
list_uuid = data.get('uuid')
|
||||
details = get_list(list_uuid)
|
||||
return jsonify(details), 200
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug = True)
|
||||
|
53
src/db.py
53
src/db.py
@@ -304,6 +304,19 @@ def remove_from_list(list_uuid, item_uuid):
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def remove_all_from_list(list_uuid):
|
||||
'''remove every items from an itemlist'''
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
DELETE
|
||||
FROM listcontent
|
||||
WHERE list_uuid = %s
|
||||
""", (list_uuid,))
|
||||
cursor.close()
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def get_lists():
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
@@ -316,6 +329,46 @@ def get_lists():
|
||||
connection.close()
|
||||
return results
|
||||
|
||||
def get_list(list_uuid):
|
||||
'''return details of a single list'''
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
SELECT name, description
|
||||
FROM itemlist
|
||||
WHERE uuid = %s
|
||||
""", (list_uuid,))
|
||||
results = cursor.fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return results[0]
|
||||
|
||||
def change_list_name(uuid, name):
|
||||
'''modify itemlist name'''
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
UPDATE itemlist
|
||||
SET name = %s
|
||||
WHERE uuid = %s
|
||||
""", (name, uuid))
|
||||
cursor.close()
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def change_list_description(uuid, description):
|
||||
'''modify itemlist description'''
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
UPDATE itemlist
|
||||
SET description = %s
|
||||
WHERE uuid = %s
|
||||
""", (description, uuid))
|
||||
cursor.close()
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def export_csv():
|
||||
'''join item and history data from database and export it in ./output.csv'''
|
||||
connection = connect_db()
|
||||
|
Reference in New Issue
Block a user