Implemented db modifications. Added manufacturer line to part info view
This commit is contained in:
@@ -42,6 +42,8 @@ def query(filter, query):
|
|||||||
s += 'LOWER(partnoalt2) like LOWER(:name) or '
|
s += 'LOWER(partnoalt2) like LOWER(:name) or '
|
||||||
if filter & (1 << 4) != 0:
|
if filter & (1 << 4) != 0:
|
||||||
s += 'LOWER(description) like LOWER(:name) or '
|
s += 'LOWER(description) like LOWER(:name) or '
|
||||||
|
if filter & (1 << 5) != 0:
|
||||||
|
s += 'LOWER(notes) like LOWER(:name) or '
|
||||||
s = s[:-4] + ';'
|
s = s[:-4] + ';'
|
||||||
s = text(s)
|
s = text(s)
|
||||||
r = db_engine.execute(s, name=query)
|
r = db_engine.execute(s, name=query)
|
||||||
@@ -60,24 +62,46 @@ def getfile(filename):
|
|||||||
|
|
||||||
@app.route('/parts/alter/<partID>', methods=['POST'])
|
@app.route('/parts/alter/<partID>', methods=['POST'])
|
||||||
def alter(partID):
|
def alter(partID):
|
||||||
'''if 'file' not in request.files:
|
s = ''
|
||||||
pass
|
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:
|
else:
|
||||||
file = request.files['file']
|
# Modify entry
|
||||||
filename = secure_filename(file.filename)
|
r = db_engine.execute(text('select * from parts where id=:id;'), id=partID)
|
||||||
file.save(os.path.join('/srv/datasheets', filename))'''
|
l = []
|
||||||
print 'Form:', request.form
|
for row in r:
|
||||||
print ' '
|
l.append(dict(row))
|
||||||
print 'Files:', request.files
|
r.close()
|
||||||
if len(request.files) == 0:
|
s = 'update parts '
|
||||||
print 'No file :('
|
s += 'set block=:block, type=:type, partno=:partno, partnoalt=:partnoalt, partnoalt2=:partnoalt2, description=:description, quantity=:quantity, datasheet=:datasheet, notes=:notes '
|
||||||
else:
|
if len(request.files) != 0:
|
||||||
print 'Oooh look, a file! :)'
|
datasheet_file = request.files['datasheet-file']
|
||||||
somefile = request.files['datasheet-file']
|
datasheet_filename = secure_filename(datasheet_file.filename)
|
||||||
print somefile.filename
|
datasheet_file.save('/srv/datasheets/' + filename)
|
||||||
filename = secure_filename(somefile.filename)
|
# TODO: Remove old datasheet
|
||||||
somefile.save('/home/davide/' + filename)
|
else:
|
||||||
print "Now it's mine"
|
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"}'
|
return '{"status":"ok"}'
|
||||||
|
|
||||||
def connect(user, password, db, host='localhost', port=5432):
|
def connect(user, password, db, host='localhost', port=5432):
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ function init_edit(partID) {
|
|||||||
block_input.val($('#block-info').text());
|
block_input.val($('#block-info').text());
|
||||||
$('#block-info').replaceWith(block_input);
|
$('#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">')
|
var partno_input = $('<input type="text" class="part-edit-input" id="partno-input" placeholder="Part number">')
|
||||||
partno_input.val($('#partno-info').text());
|
partno_input.val($('#partno-info').text());
|
||||||
$('#partno-info').replaceWith(partno_input);
|
$('#partno-info').replaceWith(partno_input);
|
||||||
@@ -45,6 +49,7 @@ function init_edit(partID) {
|
|||||||
|
|
||||||
function new_entry() {
|
function new_entry() {
|
||||||
$('#block-info').text('');
|
$('#block-info').text('');
|
||||||
|
$('#type-info').text('');
|
||||||
$('#partno-info').text('');
|
$('#partno-info').text('');
|
||||||
$('#description-info').text('');
|
$('#description-info').text('');
|
||||||
$('#quantity-info').text('');
|
$('#quantity-info').text('');
|
||||||
@@ -57,6 +62,9 @@ function end_edit() {
|
|||||||
var block_par = '<p id="block-info">' + $('#block-input').val() + '</p>';
|
var block_par = '<p id="block-info">' + $('#block-input').val() + '</p>';
|
||||||
$('#block-input').replaceWith(block_par);
|
$('#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>';
|
var partno_par = '<p id="partno-info">' + $('#partno-input').val() + '</p>';
|
||||||
$('#partno-input').replaceWith(partno_par);
|
$('#partno-input').replaceWith(partno_par);
|
||||||
|
|
||||||
@@ -78,6 +86,7 @@ function end_edit() {
|
|||||||
|
|
||||||
function save(partID) {
|
function save(partID) {
|
||||||
var block_v = $('#block-input').val();
|
var block_v = $('#block-input').val();
|
||||||
|
var type_v = $('#type-input').val();
|
||||||
var partno_v = $('#partno-input').val();
|
var partno_v = $('#partno-input').val();
|
||||||
var description_v = $('#description-input').val();
|
var description_v = $('#description-input').val();
|
||||||
var quantity_v = $('#quantity-input').val();
|
var quantity_v = $('#quantity-input').val();
|
||||||
@@ -99,6 +108,7 @@ function save(partID) {
|
|||||||
if (datasheet.length == 1)
|
if (datasheet.length == 1)
|
||||||
data.append('datasheet-file', datasheet[0]);
|
data.append('datasheet-file', datasheet[0]);
|
||||||
data.append('block', block_v);
|
data.append('block', block_v);
|
||||||
|
data.append('type', type_v);
|
||||||
data.append('partno', partnos[0]);
|
data.append('partno', partnos[0]);
|
||||||
if (partnos.length > 1)
|
if (partnos.length > 1)
|
||||||
data.append('partnoalt', partnos[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>';
|
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
|
||||||
$('#datasheet-info').replaceWith(datasheet_par);
|
$('#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) {
|
function show_part_info(partID) {
|
||||||
$.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
|
$.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
|
||||||
$('#block-info').text(text_filter(data.block));
|
$('#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));
|
$('#partno-info').text(text_filter(data.partno) + ' ' + text_filter(data.partnoalt) + ' ' + text_filter(data.partnoalt2));
|
||||||
$('#description-info').text(text_filter(data.description));
|
$('#description-info').text(text_filter(data.description));
|
||||||
$('#quantity-info').text(text_filter(data.quantity));
|
$('#quantity-info').text(text_filter(data.quantity));
|
||||||
|
|||||||
@@ -40,7 +40,12 @@
|
|||||||
|
|
||||||
<div class="details-row">
|
<div class="details-row">
|
||||||
<div class="details-item">Location: block</div>
|
<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>
|
||||||
|
|
||||||
<div class="details-row">
|
<div class="details-row">
|
||||||
|
|||||||
Reference in New Issue
Block a user