Fixed datsheet info upload check. NOW WITH TRY-CATCH!

master
Davide Bongiovanni 6 years ago
parent 08b8646374
commit 7098d19225

@ -89,7 +89,7 @@ def locationEditor():
return render_template('locationEditor.html', locations=locations, containers=getContainers()) return render_template('locationEditor.html', locations=locations, containers=getContainers())
@app.route('/parts/alterLocation/<locationID>', methods=['POST']) @app.route('/parts/alterLocation/<locationID>', methods=['POST'])
# @requires_auth @requires_auth
def alterLocation(locationID): def alterLocation(locationID):
locationID = int(locationID) locationID = int(locationID)
s = '' s = ''
@ -193,7 +193,7 @@ 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 = ''
@ -212,9 +212,13 @@ def alter(partID):
i += 1 i += 1
datasheet_file.save('/srv/datasheets/' + datasheet_filename) datasheet_file.save('/srv/datasheets/' + datasheet_filename)
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename
elif request.form.has_key('datasheet-url'): # elif request.form.has_key('datasheet-url'):
datasheet_filename = request.form['datasheet-url'] # datasheet_filename = request.form['datasheet-url']
else: else:
try:
datasheet_filename = request.form['datasheet-url']
except:
print('No docs provided')
datasheet_filename = None datasheet_filename = None
r = db_engine.execute(s, partno=request.form['partno'], r = db_engine.execute(s, partno=request.form['partno'],
description=request.form['description'], description=request.form['description'],
@ -240,9 +244,13 @@ def alter(partID):
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename
if l[0]['datasheet'] != None: if l[0]['datasheet'] != None:
os.remove('/srv/datasheets/' + l[0]['datasheet']) os.remove('/srv/datasheets/' + l[0]['datasheet'])
elif request.form.has_key('datasheet-url'): # elif request.form.has_key('datasheet-url'):
datasheet_filename = request.form['datasheet-url'] # datasheet_filename = request.form['datasheet-url']
else: else:
try:
datasheet_filename = request.form['datasheet-url']
except:
print('No docs provided')
datasheet_filename = l[0]['datasheet'] datasheet_filename = l[0]['datasheet']
s += 'where id=:id returning id;' s += 'where id=:id returning id;'
s = text(s) s = text(s)

Loading…
Cancel
Save