From bf37ea8c5cf51a740e610c861fb809ea77e00bf3 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Sat, 10 Nov 2018 15:32:09 +0100 Subject: [PATCH] Modified query to match new database --- parts/server.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/parts/server.py b/parts/server.py index cdbcaec..a85fb89 100644 --- a/parts/server.py +++ b/parts/server.py @@ -146,14 +146,14 @@ def getfile(filename): return send_from_directory('/srv/datasheets/', filename + '.pdf') @app.route('/parts/alter/', methods=['POST']) -@requires_auth +# @requires_auth def alter(partID): partID = int(partID) s = '' if partID < 0: # New entry - s = 'insert into parts (block, type, partno, partnoalt, partnoalt2, description, quantity, datasheet, notes) ' - s += 'values (:block, :type, :partno, :partnoalt, :partnoalt2, :description, :quantity, :datasheet, :notes);' + s = 'insert into parts (partno, description, datasheet, location_id) ' + s += 'values (:partno, :description, :datasheet, :location_id);' s = text(s) if len(request.files) != 0: datasheet_file = request.files['datasheet-file'] @@ -165,15 +165,10 @@ def alter(partID): datasheet_file.save('/srv/datasheets/' + datasheet_filename) else: datasheet_filename = None - r = db_engine.execute(s, block=request.form['block'], - type=request.form['type'], - partno=request.form['partno'], - partnoalt=request.form['partnoalt'], - partnoalt2=request.form['partnoalt2'], + r = db_engine.execute(s, partno=request.form['partno'], description=request.form['description'], - quantity=request.form['quantity'], datasheet=datasheet_filename, - notes=request.form['notes']) + location_id=request.form['location_id']) else: # Modify entry r = db_engine.execute(text('select * from parts where id=:id;'), id=partID) @@ -182,7 +177,7 @@ def alter(partID): l.append(dict(row)) r.close() s = 'update parts ' - s += 'set block=:block, type=:type, partno=:partno, partnoalt=:partnoalt, partnoalt2=:partnoalt2, description=:description, quantity=:quantity, datasheet=:datasheet, notes=:notes ' + s += 'set partno=:partno, description=:description, datasheet=:datasheet, location_id=:location_id ' if len(request.files) != 0: datasheet_file = request.files['datasheet-file'] datasheet_filename = secure_filename(datasheet_file.filename) @@ -197,16 +192,10 @@ def alter(partID): datasheet_filename = l[0]['datasheet'] s += 'where id=:id;' s = text(s) - r = db_engine.execute(s, location_id=request.form['block'], - type=request.form['type'], - partno=request.form['partno'], - partnoalt=request.form['partnoalt'], - partnoalt2=request.form['partnoalt2'], + r = db_engine.execute(s, partno=request.form['partno'], description=request.form['description'], - quantity=request.form['quantity'], datasheet=datasheet_filename, - notes=request.form['notes'], - id=partID) + location_id=request.form['location_id']) return '{"status":"ok"}'