diff options
author | BonfaceKilz | 2021-07-26 13:21:38 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-08-03 15:49:50 +0300 |
commit | 5e61c115a2c2be351c16fd9d1a764faecd8591fa (patch) | |
tree | 4962bc77c72567ba0bc9692dcb1b86bdb171cafd /wqflask | |
parent | b355b91f67305c4cb3ebbad994cc0ff2906eb701 (diff) | |
download | genenetwork2-5e61c115a2c2be351c16fd9d1a764faecd8591fa.tar.gz |
wqflask: views: Approve data when the "approve" button is clicked
* wqflask/wqflask/views.py (approve_data): New function.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/views.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index cf7b5552..1d50bdff 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -33,6 +33,7 @@ from gn3.db import fetchall from gn3.db import fetchone from gn3.db import insert from gn3.db import update +from gn3.db import update_raw from gn3.db.metadata_audit import MetadataAudit from gn3.db.phenotypes import Phenotype from gn3.db.phenotypes import Probeset @@ -1387,3 +1388,41 @@ def display_diffs_admin(): return render_template("display_files.html", files=files) + +@app.route("/data-samples/approve/<name>") +def approve_data(name): + sample_data = {} + conn = MySQLdb.Connect(db=current_app.config.get("DB_NAME"), + user=current_app.config.get("DB_USER"), + passwd=current_app.config.get("DB_PASS"), + host=current_app.config.get("DB_HOST")) + with open(os.path.join("/tmp/sample-data/diffs", name), 'r') as myfile: + sample_data = json.load(myfile) + modifications = [d for d in sample_data.get("Modifications")] + for modification in modifications: + if modifications.get("current"): + (strain_id, publish_id, + strain_name, + value, se, count) = modification.get("Current").split(",") + row_counts = update_sample_data( + conn=conn, + strain_name=strain_name, + strain_id=int(strain_id), + publish_data_id=int(PUBLISH_ID), + value=value, + error=se, + count=int(count) + ) + insert(conn, + table="metadata_audit", + data=MetadataAudit( + dataset_id=sample_data.get("publishdata_id"), + editor=sample_data.get("author"), + json_data=json.dumps(sample_data))) + + # Once data is approved, rename it! + os.rename(os.path.join("/tmp/sample-data/diffs", name), + os.path.join("/tmp/sample-data/diffs", + f"{name}.approved")) + return redirect("/data/approve/") + |