From e72ee8b00d0e2d0456f05160916211a1536054c8 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 19 Apr 2023 16:15:53 +0300 Subject: oauth2: Link the data --- wqflask/wqflask/oauth2/data.py | 27 ++++++++++++++++++++++ .../templates/oauth2/data-list-phenotype.html | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py index d7be85f0..68a98d98 100644 --- a/wqflask/wqflask/oauth2/data.py +++ b/wqflask/wqflask/oauth2/data.py @@ -283,6 +283,7 @@ def link_mrna_data(): species_name=form["species_name"], dataset_type="mrna")) def __link_error__(err): + error = process_error(err) flash(f"{err['error']}: {err['error_description']}", "alert-danger") return link_source_url @@ -296,3 +297,29 @@ def link_mrna_data(): "selected": tuple(json.loads(dataset) for dataset in form.getlist("selected")) }).either(lambda err: __link_error__(process_error(err)), __link_success__) + +@data.route("/link/phenotype", methods=["POST"]) +def link_phenotype_data(): + """Link phenotype data to a group.""" + form = request.form + link_source_url = redirect(url_for("oauth2.data.list_data")) + if bool(form.get("species_name")): + link_source_url = redirect(url_for( + "oauth2.data.list_data_by_species_and_dataset", + species_name=form["species_name"], dataset_type="mrna")) + + def __link_error__(err): + error = process_error(err) + flash(f"{error['error']}: {error['error_description']}", "alert-danger") + return link_source_url + + def __link_success__(success): + flash(success["description"], "alert-success") + return link_source_url + + return oauth2_post("oauth2/data/link/phenotype", json={ + "species_name": form.get("species_name"), + "group_id": form.get("group_id"), + "selected": tuple( + json.loads(trait) for trait in form.getlist("selected"))}).either( + __link_error__, __link_success__) diff --git a/wqflask/wqflask/templates/oauth2/data-list-phenotype.html b/wqflask/wqflask/templates/oauth2/data-list-phenotype.html index 8329e023..b79b3096 100644 --- a/wqflask/wqflask/templates/oauth2/data-list-phenotype.html +++ b/wqflask/wqflask/templates/oauth2/data-list-phenotype.html @@ -24,7 +24,9 @@