aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-05-16 14:05:32 +0300
committerFrederick Muriuki Muriithi2023-05-16 14:05:32 +0300
commit8b99c746771692af9fa01037b5b03475bf77ba97 (patch)
tree2dc011a1332579f6c94b0f869e45ae204bdcd6af /wqflask
parentd5763a88090f57febb58fdae0cbfb24c76ffed6c (diff)
downloadgenenetwork2-8b99c746771692af9fa01037b5b03475bf77ba97.tar.gz
auth: View collection details from GN3 endpoint
Retrieve a specific collection's details from the GN3 endpoint rather than from the session, as was done previously.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/collect.py90
1 files changed, 53 insertions, 37 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index b6ca6015..b64270e0 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -24,6 +24,7 @@ from base.trait import jsonable
from base.data_set import create_dataset
from wqflask.oauth2 import session
+from wqflask.oauth2.session import session_info
from wqflask.oauth2.checks import user_logged_in
from wqflask.oauth2.request_utils import process_error
from wqflask.oauth2.client import oauth2_get, no_token_get, no_token_post
@@ -288,47 +289,62 @@ def view_collection():
params = request.args
uc_id = params['uc_id']
- uc = next(
- (collection for collection in g.user_session.user_collections if collection["id"] == uc_id))
- traits = uc["members"]
-
- trait_obs = []
- json_version = []
-
- for atrait in traits:
- if ':' not in atrait:
- continue
- name, dataset_name = atrait.split(':')
- if dataset_name == "Temp":
- group = name.split("_")[2]
- dataset = create_dataset(
- dataset_name, dataset_type="Temp", group_name=group)
- trait_ob = create_trait(name=name, dataset=dataset)
- else:
- dataset = create_dataset(dataset_name)
- trait_ob = create_trait(name=name, dataset=dataset)
- trait_ob = retrieve_trait_info(
- trait_ob, dataset, get_qtl_info=True)
- trait_obs.append(trait_ob)
+ request_data = {
+ "uri_path": f"oauth2/user/collections/{uc_id}/view",
+ "json": {"anon_id": str(session_info()["anon_id"])}
+ }
+ if user_logged_in():
+ coll = oauth2_post(**request_data)
+ else:
+ coll = no_token_post(**request_data)
+
+ def __view__(uc):
+ traits = uc["members"]
+
+ trait_obs = []
+ json_version = []
+
+ for atrait in traits:
+ if ':' not in atrait:
+ continue
+ name, dataset_name = atrait.split(':')
+ if dataset_name == "Temp":
+ group = name.split("_")[2]
+ dataset = create_dataset(
+ dataset_name, dataset_type="Temp", group_name=group)
+ trait_ob = create_trait(name=name, dataset=dataset)
+ else:
+ dataset = create_dataset(dataset_name)
+ trait_ob = create_trait(name=name, dataset=dataset)
+ trait_ob = retrieve_trait_info(
+ trait_ob, dataset, get_qtl_info=True)
+ trait_obs.append(trait_ob)
- trait_json = jsonable(trait_ob)
- trait_json['trait_info_str'] = trait_info_str(trait_ob)
+ trait_json = jsonable(trait_ob)
+ trait_json['trait_info_str'] = trait_info_str(trait_ob)
- json_version.append(trait_json)
+ json_version.append(trait_json)
- collection_info = dict(
- trait_obs=trait_obs,
- uc=uc,
- heatmap_data_url=urljoin(GN_SERVER_URL, "heatmaps/clustered"))
+ collection_info = dict(
+ trait_obs=trait_obs,
+ uc=uc,
+ heatmap_data_url=urljoin(GN_SERVER_URL, "heatmaps/clustered"))
- if "json" in params:
- return json.dumps(json_version)
- else:
- return render_template(
- "collections/view.html",
- traits_json=json_version,
- trait_info_str=trait_info_str,
- **collection_info)
+ if "json" in params:
+ return json.dumps(json_version)
+ else:
+ return render_template(
+ "collections/view.html",
+ traits_json=json_version,
+ trait_info_str=trait_info_str,
+ **collection_info)
+
+ def __error__(err):
+ error = process_error(err)
+ flash(f"{error['error']}: {error['error_description']}", "alert-danger")
+ return redirect(url_for("list_collections"))
+
+ return coll.either(__error__, __view__)
@app.route("/collections/change_name", methods=('POST',))
def change_collection_name():