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' datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf'
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
elif request.form.has_key('datasheet-url'):
datasheet_filename = request.form['datasheet-url']
else: else:
datasheet_filename = None datasheet_filename = None
r = db_engine.execute(s, partno=request.form['partno'], r = db_engine.execute(s, partno=request.form['partno'],
@ -234,8 +237,11 @@ def alter(partID):
datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf'
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
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'):
datasheet_filename = request.form['datasheet-url']
else: else:
datasheet_filename = l[0]['datasheet'] datasheet_filename = l[0]['datasheet']
s += 'where id=:id returning id;' s += 'where id=:id returning id;'

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

Loading…
Cancel
Save