Handling datasheet URLs

master
Davide Bongiovanni 6 years ago
parent caf1efce0c
commit da5339a473

@ -211,6 +211,9 @@ def alter(partID):
datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf'
i += 1
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename
elif request.form.has_key('datasheet-url'):
datasheet_filename = request.form['datasheet-url']
else:
datasheet_filename = None
r = db_engine.execute(s, partno=request.form['partno'],
@ -234,8 +237,11 @@ def alter(partID):
datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf'
i += 1
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename
if l[0]['datasheet'] != None:
os.remove('/srv/datasheets/' + l[0]['datasheet'])
elif request.form.has_key('datasheet-url'):
datasheet_filename = request.form['datasheet-url']
else:
datasheet_filename = l[0]['datasheet']
s += 'where id=:id returning id;'

@ -65,6 +65,7 @@ function save(partID) {
var partno_v = $('input[name=partno-input]').val();
var description_v = $('input[name=description-input]').val();
var datasheet = $('table#details tr#datasheet td input')[0].files;
var datasheet_url_v = $('input[name=datasheet-url-input]').val();
if(partno_v.length == 0){
alert('Please enter a part number.');
return;
@ -89,6 +90,8 @@ function save(partID) {
return;
}
data.append('datasheet-file', datasheet[0]);
} else if (datasheet_url_v.length > 0) {
data.append('datasheet-url', datasheet_url_v);
}
data.append('partno', partno_v);
data.append('location_id', location_id_v)
@ -162,8 +165,8 @@ function show_part_info(partID) {
$('table#details tr#description td input').val(text_filter(data.description));
container_onchange();
if (data.datasheet != null) {
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="parts/getfile/' + data.datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>'));
$('#datasheet-input').val(data.datasheet);
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="' + data.datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>'));
$('input[name=datasheet-url-input]').val(data.datasheet);
}
else
$('tr#datasheet-head td').text('DATASHEET: ');

Loading…
Cancel
Save