|
|
@ -146,14 +146,14 @@ def getfile(filename):
|
|
|
|
return send_from_directory('/srv/datasheets/', filename + '.pdf')
|
|
|
|
return send_from_directory('/srv/datasheets/', filename + '.pdf')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/parts/alter/<partID>', methods=['POST'])
|
|
|
|
@app.route('/parts/alter/<partID>', methods=['POST'])
|
|
|
|
@requires_auth
|
|
|
|
# @requires_auth
|
|
|
|
def alter(partID):
|
|
|
|
def alter(partID):
|
|
|
|
partID = int(partID)
|
|
|
|
partID = int(partID)
|
|
|
|
s = ''
|
|
|
|
s = ''
|
|
|
|
if partID < 0:
|
|
|
|
if partID < 0:
|
|
|
|
# New entry
|
|
|
|
# New entry
|
|
|
|
s = 'insert into parts (block, type, partno, partnoalt, partnoalt2, description, quantity, datasheet, notes) '
|
|
|
|
s = 'insert into parts (partno, description, datasheet, location_id) '
|
|
|
|
s += 'values (:block, :type, :partno, :partnoalt, :partnoalt2, :description, :quantity, :datasheet, :notes);'
|
|
|
|
s += 'values (:partno, :description, :datasheet, :location_id);'
|
|
|
|
s = text(s)
|
|
|
|
s = text(s)
|
|
|
|
if len(request.files) != 0:
|
|
|
|
if len(request.files) != 0:
|
|
|
|
datasheet_file = request.files['datasheet-file']
|
|
|
|
datasheet_file = request.files['datasheet-file']
|
|
|
@ -165,15 +165,10 @@ def alter(partID):
|
|
|
|
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
|
|
|
|
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
datasheet_filename = None
|
|
|
|
datasheet_filename = None
|
|
|
|
r = db_engine.execute(s, block=request.form['block'],
|
|
|
|
r = db_engine.execute(s, partno=request.form['partno'],
|
|
|
|
type=request.form['type'],
|
|
|
|
|
|
|
|
partno=request.form['partno'],
|
|
|
|
|
|
|
|
partnoalt=request.form['partnoalt'],
|
|
|
|
|
|
|
|
partnoalt2=request.form['partnoalt2'],
|
|
|
|
|
|
|
|
description=request.form['description'],
|
|
|
|
description=request.form['description'],
|
|
|
|
quantity=request.form['quantity'],
|
|
|
|
|
|
|
|
datasheet=datasheet_filename,
|
|
|
|
datasheet=datasheet_filename,
|
|
|
|
notes=request.form['notes'])
|
|
|
|
location_id=request.form['location_id'])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Modify entry
|
|
|
|
# Modify entry
|
|
|
|
r = db_engine.execute(text('select * from parts where id=:id;'), id=partID)
|
|
|
|
r = db_engine.execute(text('select * from parts where id=:id;'), id=partID)
|
|
|
@ -182,7 +177,7 @@ def alter(partID):
|
|
|
|
l.append(dict(row))
|
|
|
|
l.append(dict(row))
|
|
|
|
r.close()
|
|
|
|
r.close()
|
|
|
|
s = 'update parts '
|
|
|
|
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:
|
|
|
|
if len(request.files) != 0:
|
|
|
|
datasheet_file = request.files['datasheet-file']
|
|
|
|
datasheet_file = request.files['datasheet-file']
|
|
|
|
datasheet_filename = secure_filename(datasheet_file.filename)
|
|
|
|
datasheet_filename = secure_filename(datasheet_file.filename)
|
|
|
@ -197,16 +192,10 @@ def alter(partID):
|
|
|
|
datasheet_filename = l[0]['datasheet']
|
|
|
|
datasheet_filename = l[0]['datasheet']
|
|
|
|
s += 'where id=:id;'
|
|
|
|
s += 'where id=:id;'
|
|
|
|
s = text(s)
|
|
|
|
s = text(s)
|
|
|
|
r = db_engine.execute(s, location_id=request.form['block'],
|
|
|
|
r = db_engine.execute(s, partno=request.form['partno'],
|
|
|
|
type=request.form['type'],
|
|
|
|
|
|
|
|
partno=request.form['partno'],
|
|
|
|
|
|
|
|
partnoalt=request.form['partnoalt'],
|
|
|
|
|
|
|
|
partnoalt2=request.form['partnoalt2'],
|
|
|
|
|
|
|
|
description=request.form['description'],
|
|
|
|
description=request.form['description'],
|
|
|
|
quantity=request.form['quantity'],
|
|
|
|
|
|
|
|
datasheet=datasheet_filename,
|
|
|
|
datasheet=datasheet_filename,
|
|
|
|
notes=request.form['notes'],
|
|
|
|
location_id=request.form['location_id'])
|
|
|
|
id=partID)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return '{"status":"ok"}'
|
|
|
|
return '{"status":"ok"}'
|
|
|
|