From 657eeffde2b727e1656e9e1f1a346d15ea1ac5f9 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Sat, 28 Dec 2024 10:54:07 +0100 Subject: [PATCH] Added upload button to instructions --- app.py | 35 +++++++++++++++++++++++++++++++++++ templates/index.html | 4 ++++ 2 files changed, 39 insertions(+) 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 ''' + + Upload new File +

Upload new File

+
+ + +
+ ''' + @app.route('/delete/',methods=['POST', 'GET']) def delete(tmp): diff --git a/templates/index.html b/templates/index.html index a61f344..84988ba 100644 --- a/templates/index.html +++ b/templates/index.html @@ -134,6 +134,10 @@ display: none !important; Config + + + Upload +