"""Entry-point module""" import os from werkzeug.utils import secure_filename from flask import ( flash, request, url_for, redirect, Blueprint, render_template, current_app as app) entrybp = Blueprint("entry", __name__) @entrybp.route("/", methods=["GET", "POST"]) def upload_file(): """Enables uploading the files""" if request.method == "GET": return render_template("index.html") errors = False if request.form["filetype"] not in ("average", "standard_error"): flash("Invalid file type provided.", "alert-error") errors = True if ("qc_text_file" not in request.files or request.files["qc_text_file"].filename == ""): flash("No file was uploaded.", "alert-error") errors = True text_file = request.files["qc_text_file"] if text_file.mimetype != "text/tab-separated-values": flash("Invalid file! Expected a tab-separated-values file.", "alert-error") errors = True if errors: return render_template("index.html") filename = secure_filename(text_file.filename) if not os.path.exists(app.config["UPLOAD_FOLDER"]): os.mkdir(app.config["UPLOAD_FOLDER"]) filepath = os.path.join(app.config["UPLOAD_FOLDER"], filename) text_file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename)) return redirect(url_for( "parse.parse", filename=filename, filetype=request.form["filetype"]))