diff options
-rw-r--r-- | uploader/genotypes/views.py | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index 3c20b52..7b5994e 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -9,6 +9,7 @@ from flask import (flash, current_app as app) from uploader.ui import make_template_renderer +from uploader.oauth2.client import oauth2_post from uploader.authorisation import require_login from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id @@ -177,8 +178,37 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable= form["geno-dataset-fullname"], form["geno-dataset-shortname"]) - flash("Successfully created genotype dataset." - "alert-success") - return redirect(url_for("species.populations.genotypes.list_genotypes", - species_id=species["SpeciesId"], - population_id=population["Id"])) + def __success__(_success): + flash("Successfully created genotype dataset." "alert-success") + return redirect(url_for( + "species.populations.genotypes.list_genotypes", + species_id=species["SpeciesId"], + population_id=population["Id"])) + + def __fail__(error): + msg = "There was an error creating the genotype dataset." + if issubclass(type(error), Exception): + app.logger.debug("\n\n%s (Exception)\n\n", msg, exc_info=True) + raise error + if issubclass(type(error), Response): + try: + _data = error.json() + except Exception as _exc: + raise Exception(error.content) from _exc + raise Exception(_data) + + app.logger.debug("\n\n%s\n\n", msg) + raise Exception(error) + + return oauth2_post( + "auth/resource/genotypes/create", + json={ + **dict(request.form), + "species_id": species["SpeciesId"], + "population_id": population["Id"], + "dataset_name": form["geno-dataset-name"], + "dataset_fullname": form["geno-dataset-fullname"], + "dataset_shortname": form["geno-dataset-shortname"], + "public": "on" + } + ).either(__fail__, __success__) |