aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/oauth2/client.py9
-rw-r--r--wqflask/wqflask/oauth2/data.py26
-rw-r--r--wqflask/wqflask/templates/oauth2/data-list-genotype.html5
3 files changed, 37 insertions, 3 deletions
diff --git a/wqflask/wqflask/oauth2/client.py b/wqflask/wqflask/oauth2/client.py
index 999bbfc8..0cecd965 100644
--- a/wqflask/wqflask/oauth2/client.py
+++ b/wqflask/wqflask/oauth2/client.py
@@ -1,4 +1,5 @@
"""Common oauth2 client utilities."""
+from typing import Optional
from urllib.parse import urljoin
from flask import session, current_app as app
@@ -29,13 +30,17 @@ def oauth2_get(uri_path: str, data: dict = {}) -> Either:
return Left(resp)
-def oauth2_post(uri_path: str, data: dict) -> Either:
+def oauth2_post(
+ uri_path: str, data: Optional[dict] = None, json: Optional[dict] = None,
+ **kwargs) -> Either:
token = session.get("oauth2_token")
config = app.config
client = OAuth2Session(
config["OAUTH2_CLIENT_ID"], config["OAUTH2_CLIENT_SECRET"],
token=token, scope=SCOPE)
- resp = client.post(urljoin(config["GN_SERVER_URL"], uri_path), data=data)
+ resp = client.post(
+ urljoin(config["GN_SERVER_URL"], uri_path), data=data, json=json,
+ **kwargs)
if resp.status_code == 200:
return Right(resp.json())
diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py
index 1dcacb7e..e1b33b56 100644
--- a/wqflask/wqflask/oauth2/data.py
+++ b/wqflask/wqflask/oauth2/data.py
@@ -1,4 +1,5 @@
"""Handle linking data to groups."""
+import json
from urllib.parse import urljoin
from flask import (
@@ -154,3 +155,28 @@ def link_data():
except AssertionError as aserr:
flash("You must provide all the expected data.", "alert-danger")
return redirect(url_for("oauth2.data.list_data"))
+
+@data.route("/link/genotype", methods=["POST"])
+def link_genotype_data():
+ """Link genotype 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="genotype"))
+
+ def __link_error__(err):
+ flash(f"{err['error']}: {err['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/genotype", json={
+ "species_name": form.get("species_name"),
+ "group_id": form.get("group_id"),
+ "selected_datasets": tuple(json.loads(dataset) for dataset
+ in form.getlist("selected_datasets"))
+ }).either(lambda err: __link_error__(process_error(err)), __link_success__)
diff --git a/wqflask/wqflask/templates/oauth2/data-list-genotype.html b/wqflask/wqflask/templates/oauth2/data-list-genotype.html
index 3b7cfc1f..54479251 100644
--- a/wqflask/wqflask/templates/oauth2/data-list-genotype.html
+++ b/wqflask/wqflask/templates/oauth2/data-list-genotype.html
@@ -23,9 +23,12 @@
</div>
<div class="row">
- <form id="frm-link-genotypes">
+ <form id="frm-link-genotypes" method="POST"
+ action="{{url_for('oauth2.data.link_genotype_data')}}">
<legend>Link Genotype Traits to Group</legend>
+ <input type="hidden" name="species_name" value="{{species_name}}" />
+
<div class="form-group">
<label for="select-group">Group</label>
<select id="select-group" name="group_id" required="required"