|
|
|
@ -42,6 +42,8 @@ def query(filter, query):
|
|
|
|
|
s += 'LOWER(partnoalt2) like LOWER(:name) or '
|
|
|
|
|
if filter & (1 << 4) != 0:
|
|
|
|
|
s += 'LOWER(description) like LOWER(:name) or '
|
|
|
|
|
if filter & (1 << 5) != 0:
|
|
|
|
|
s += 'LOWER(notes) like LOWER(:name) or '
|
|
|
|
|
s = s[:-4] + ';'
|
|
|
|
|
s = text(s)
|
|
|
|
|
r = db_engine.execute(s, name=query)
|
|
|
|
@ -60,24 +62,46 @@ def getfile(filename):
|
|
|
|
|
|
|
|
|
|
@app.route('/parts/alter/<partID>', methods=['POST'])
|
|
|
|
|
def alter(partID):
|
|
|
|
|
'''if 'file' not in request.files:
|
|
|
|
|
pass
|
|
|
|
|
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 = text(s)
|
|
|
|
|
if len(request.files) != 0:
|
|
|
|
|
datasheet_file = request.files['datasheet-file']
|
|
|
|
|
datasheet_filename = secure_filename(datasheet_file.filename)
|
|
|
|
|
datasheet_file.save('/srv/datasheets/' + filename)
|
|
|
|
|
else:
|
|
|
|
|
datasheet_filename = ''
|
|
|
|
|
else:
|
|
|
|
|
file = request.files['file']
|
|
|
|
|
filename = secure_filename(file.filename)
|
|
|
|
|
file.save(os.path.join('/srv/datasheets', filename))'''
|
|
|
|
|
print 'Form:', request.form
|
|
|
|
|
print ' '
|
|
|
|
|
print 'Files:', request.files
|
|
|
|
|
if len(request.files) == 0:
|
|
|
|
|
print 'No file :('
|
|
|
|
|
else:
|
|
|
|
|
print 'Oooh look, a file! :)'
|
|
|
|
|
somefile = request.files['datasheet-file']
|
|
|
|
|
print somefile.filename
|
|
|
|
|
filename = secure_filename(somefile.filename)
|
|
|
|
|
somefile.save('/home/davide/' + filename)
|
|
|
|
|
print "Now it's mine"
|
|
|
|
|
# Modify entry
|
|
|
|
|
r = db_engine.execute(text('select * from parts where id=:id;'), id=partID)
|
|
|
|
|
l = []
|
|
|
|
|
for row in r:
|
|
|
|
|
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 '
|
|
|
|
|
if len(request.files) != 0:
|
|
|
|
|
datasheet_file = request.files['datasheet-file']
|
|
|
|
|
datasheet_filename = secure_filename(datasheet_file.filename)
|
|
|
|
|
datasheet_file.save('/srv/datasheets/' + filename)
|
|
|
|
|
# TODO: Remove old datasheet
|
|
|
|
|
else:
|
|
|
|
|
datasheet_filename = l['datasheet']
|
|
|
|
|
s += 'where id=:id;'
|
|
|
|
|
s = text(s)
|
|
|
|
|
|
|
|
|
|
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'],
|
|
|
|
|
description=request.form['description'],
|
|
|
|
|
quantity=request.form['quantity'],
|
|
|
|
|
datasheet=datasheet_filename,
|
|
|
|
|
notes=request.form['notes'])
|
|
|
|
|
return '{"status":"ok"}'
|
|
|
|
|
|
|
|
|
|
def connect(user, password, db, host='localhost', port=5432):
|
|
|
|
|