diff options
Diffstat (limited to 'qc_app')
-rw-r--r-- | qc_app/upload/rqtl2.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 53e7f3f..d60ea65 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -103,6 +103,9 @@ def create_population(species_id: int): pgsrc="create-population"), code=307) +class __RequestError__(Exception): #pylint: disable=[invalid-name] + """Internal class to avoid pylint's `too-many-return-statements` error.""" + @rqtl2.route(("/upload/species/<int:species_id>/population/<int:population_id>" "/rqtl2-bundle"), methods=["GET", "POST"]) @@ -133,22 +136,21 @@ def upload_rqtl2_bundle(species_id: int, population_id: int): species=species, population=population) + if not bool(request.files.get("rqtl2_bundle")): + raise __RequestError__("No R/qtl2 zip bundle provided.") + the_file = save_file( - request.files.get("rqtl2_bundle"), Path(app.config["UPLOAD_FOLDER"])) + request.files["rqtl2_bundle"], Path(app.config["UPLOAD_FOLDER"])) if not bool(the_file): - flash("Please provide a valid R/qtl2 zip bundle.", - "alert-error alert-danger error-rqtl2") - return this_page_with_errors + raise __RequestError__("Please provide a valid R/qtl2 zip bundle.") - if not is_zipfile(the_file): - flash("Invalid file! Expected a zip file.", - "alert-error alert-danger error-rqtl2") - return this_page_with_errors + if not is_zipfile(str(the_file)): + raise __RequestError__("Invalid file! Expected a zip file.") try: - with ZipFile(the_file, "r") as zfile: + with ZipFile(str(the_file), "r") as zfile: r_qtl2.validate_bundle(zfile) return "WOULD PROCESS THE BUNDLE..." - except InvalidFormat as invf: - flash("".join(invf.args), "alert-error alert-danger error-rqtl2") + except (InvalidFormat, __RequestError__) as exc: + flash("".join(exc.args), "alert-error alert-danger error-rqtl2") return this_page_with_errors |