diff --git a/server.py b/server.py index 8eb3643..8438c44 100644 --- a/server.py +++ b/server.py @@ -4,7 +4,8 @@ import sqlalchemy from sqlalchemy.sql import select from sqlalchemy.sql import text from flask import Flask -from flask import render_template, send_from_directory +from flask import render_template, send_from_directory, request +from werkzeug.utils import secure_filename app = Flask(__name__) @@ -57,6 +58,16 @@ def getfile(filename): return send_from_directory('/srv/datasheets/', 'filename') +@app.route('/parts/alter/', methods=['POST']) +def alter(partID): + '''if 'file' not in request.files: + pass + else: + file = request.files['file'] + filename = secure_filename(file.filename) + file.save(os.path.join('/srv/datasheets', filename))''' + print dict(request) + def connect(user, password, db, host='localhost', port=5432): '''Returns a connection and a metadata object''' # We connect with the help of the PostgreSQL URL diff --git a/static/script.js b/static/script.js index 4a9ef9e..d34e54b 100644 --- a/static/script.js +++ b/static/script.js @@ -94,7 +94,10 @@ function save(partID) { partnos = partno_v.split(' '); - if (datasheet.length == 1) { + if (datasheet.length == 0) { + datasheet = []; + datasheet[0] = ''; + } $.ajax({ // Your server script to process the upload url: 'https://www.elab.kth.se/parts/alter/' + partID, @@ -127,7 +130,7 @@ function save(partID) { return xhr; }, }); - } + end_edit(); }