Implemented db modifications. Added manufacturer line to part info view

pull/3/head
Davide Bongiovanni 8 years ago
parent 550d79910e
commit d8585207a4

@ -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):

@ -20,6 +20,10 @@ function init_edit(partID) {
block_input.val($('#block-info').text());
$('#block-info').replaceWith(block_input);
var type_input = $('<input type="text" class="part-edit-input" id="type-input" placeholder="Manufacturer">')
type_input.val($('#type-info').text());
$('#type-info').replaceWith(type_input);
var partno_input = $('<input type="text" class="part-edit-input" id="partno-input" placeholder="Part number">')
partno_input.val($('#partno-info').text());
$('#partno-info').replaceWith(partno_input);
@ -45,6 +49,7 @@ function init_edit(partID) {
function new_entry() {
$('#block-info').text('');
$('#type-info').text('');
$('#partno-info').text('');
$('#description-info').text('');
$('#quantity-info').text('');
@ -57,6 +62,9 @@ function end_edit() {
var block_par = '<p id="block-info">' + $('#block-input').val() + '</p>';
$('#block-input').replaceWith(block_par);
var type_par = '<p id="type-info">' + $('#type-input').val() + '</p>';
$('#type-input').replaceWith(type_par);
var partno_par = '<p id="partno-info">' + $('#partno-input').val() + '</p>';
$('#partno-input').replaceWith(partno_par);
@ -78,6 +86,7 @@ function end_edit() {
function save(partID) {
var block_v = $('#block-input').val();
var type_v = $('#type-input').val();
var partno_v = $('#partno-input').val();
var description_v = $('#description-input').val();
var quantity_v = $('#quantity-input').val();
@ -99,6 +108,7 @@ function save(partID) {
if (datasheet.length == 1)
data.append('datasheet-file', datasheet[0]);
data.append('block', block_v);
data.append('type', type_v);
data.append('partno', partnos[0]);
if (partnos.length > 1)
data.append('partnoalt', partnos[1]);
@ -124,6 +134,9 @@ function save(partID) {
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
$('#datasheet-info').replaceWith(datasheet_par);
},
error: function() {
alert("Couldn't update the part information. Please retry.");
}
});
@ -141,6 +154,7 @@ function text_filter(string) {
function show_part_info(partID) {
$.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
$('#block-info').text(text_filter(data.block));
$('#type-info').text(text_filter(data.type));
$('#partno-info').text(text_filter(data.partno) + ' ' + text_filter(data.partnoalt) + ' ' + text_filter(data.partnoalt2));
$('#description-info').text(text_filter(data.description));
$('#quantity-info').text(text_filter(data.quantity));

@ -40,7 +40,12 @@
<div class="details-row">
<div class="details-item">Location: block</div>
<div class="details-content"><p id="block-info">1</p></div>
<div class="details-content"><p id="block-info"></p></div>
</div>
<div class="details-row">
<div class="details-item">Manufacturer</div>
<div class="details-content"><p id="type-info"></p></div>
</div>
<div class="details-row">

Loading…
Cancel
Save