Server returns id of added/modified part. Removed authentication for now.
This commit is contained in:
+8
-4
@@ -183,10 +183,11 @@ def getfile(filename):
|
||||
def alter(partID):
|
||||
partID = int(partID)
|
||||
s = ''
|
||||
r = {}
|
||||
if partID < 0:
|
||||
# New entry
|
||||
s = 'insert into parts (partno, description, datasheet, location_id) '
|
||||
s += 'values (:partno, :description, :datasheet, :location_id);'
|
||||
s += 'values (:partno, :description, :datasheet, :location_id) returning id;'
|
||||
s = text(s)
|
||||
if len(request.files) != 0:
|
||||
datasheet_file = request.files['datasheet-file']
|
||||
@@ -223,17 +224,20 @@ def alter(partID):
|
||||
os.remove('/srv/datasheets/' + l[0]['datasheet'])
|
||||
else:
|
||||
datasheet_filename = l[0]['datasheet']
|
||||
s += 'where id=:id;'
|
||||
s += 'where id=:id returning id;'
|
||||
s = text(s)
|
||||
r = db_engine.execute(s, partno=request.form['partno'],
|
||||
description=request.form['description'],
|
||||
datasheet=datasheet_filename,
|
||||
location_id=request.form['location_id'],
|
||||
id=partID)
|
||||
return '{"status":"ok"}'
|
||||
|
||||
new_id = r.fetchone()[0]
|
||||
r.close()
|
||||
return '{"status":"ok", "part_id" : ' + str(new_id) + '}'
|
||||
|
||||
@app.route('/parts/delete/<partID>')
|
||||
@requires_auth
|
||||
# @requires_auth
|
||||
def delete(partID):
|
||||
if partID < 0:
|
||||
abort(400)
|
||||
|
||||
Reference in New Issue
Block a user