diff --git a/app.py b/app.py index 395d412..90b3f35 100644 --- a/app.py +++ b/app.py @@ -15,6 +15,7 @@ import eventlet from downloadRB import download_and_unzip,get_nil_images,get_retired_sets from db import initialize_database,get_rows,delete_tables from werkzeug.middleware.proxy_fix import ProxyFix +from werkzeug.utils import secure_filename app = Flask(__name__) @@ -29,6 +30,9 @@ else: DIRECTORY = os.path.join(os.getcwd(), 'static', 'instructions') +UPLOAD_FOLDER = DIRECTORY +ALLOWED_EXTENSIONS = {'pdf'} +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER @app.route('/favicon.ico') @@ -80,6 +84,37 @@ def hyphen_split(a): return a.split("-")[0] return "-".join(a.split("-", 2)[:2]) +def allowed_file(filename): + return '.' in filename and \ + filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + +@app.route('/upload',methods=['GET','POST']) +def uploadInst(): + if request.method == 'POST': + # check if the post request has the file part + if 'file' not in request.files: + flash('No file part') + return redirect(request.url) + file = request.files['file'] + # If the user does not select a file, the browser submits an + # empty file without a filename. + if file.filename == '': + flash('No selected file') + return redirect(request.url) + if file and allowed_file(file.filename): + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + return redirect('/') + return ''' + +