aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2021-10-27 14:28:12 +0300
committerBonfaceKilz2021-10-28 08:34:35 +0300
commit4bc8c4d2b5fcfc164026e9a924b3b784af8957ea (patch)
treeb1e336fe5ec8c4528044ae0f4583bbefe10257cb
parent7547801f579ded3b8f94d98bc954a530d5275682 (diff)
downloadgenenetwork2-4bc8c4d2b5fcfc164026e9a924b3b784af8957ea.tar.gz
Move endpoint for updating probeset to metadata_edits.py as a bp
-rw-r--r--wqflask/wqflask/metadata_edits.py59
-rw-r--r--wqflask/wqflask/views.py58
2 files changed, 59 insertions, 58 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 08ff4704..ef9dc127 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -278,3 +278,62 @@ def update_phenotype(dataset_id: str, name: str):
flash(f"Diff-data: \n{diff_data}\nhas been uploaded", "success")
return redirect(f"/datasets/{dataset_id}/traits/{name}"
f"?resource-id={request.args.get('resource-id')}")
+
+
+@metadata_edit.route("/traits/<name>", methods=["POST"])
+@edit_access_required
+def update_probeset(name: str):
+ 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"))
+ data_ = request.form.to_dict()
+ probeset_ = {
+ "id_": data_.get("id"),
+ "symbol": data_.get("symbol"),
+ "description": data_.get("description"),
+ "probe_target_description": data_.get("probe_target_description"),
+ "chr_": data_.get("chr"),
+ "mb": data_.get("mb"),
+ "alias": data_.get("alias"),
+ "geneid": data_.get("geneid"),
+ "homologeneid": data_.get("homologeneid"),
+ "unigeneid": data_.get("unigeneid"),
+ "omim": data_.get("OMIM"),
+ "refseq_transcriptid": data_.get("refseq_transcriptid"),
+ "blatseq": data_.get("blatseq"),
+ "targetseq": data_.get("targetseq"),
+ "strand_probe": data_.get("Strand_Probe"),
+ "probe_set_target_region": data_.get("probe_set_target_region"),
+ "probe_set_specificity": data_.get("probe_set_specificity"),
+ "probe_set_blat_score": data_.get("probe_set_blat_score"),
+ "probe_set_blat_mb_start": data_.get("probe_set_blat_mb_start"),
+ "probe_set_blat_mb_end": data_.get("probe_set_blat_mb_end"),
+ "probe_set_strand": data_.get("probe_set_strand"),
+ "probe_set_note_by_rw": data_.get("probe_set_note_by_rw"),
+ "flag": data_.get("flag")
+ }
+ diff_data = {}
+ author = ((g.user_session.record.get(b"user_id") or b"").decode("utf-8")
+ or g.user_session.record.get("user_id") or "")
+ if (updated_probeset := update(
+ conn, "ProbeSet",
+ data=Probeset(**probeset_),
+ where=Probeset(id_=data_.get("id")))):
+ diff_data.update({"Probeset": diff_from_dict(old={
+ k: data_.get(f"old_{k}") for k, v in probeset_.items()
+ if v is not None}, new=probeset_)})
+ if diff_data:
+ diff_data.update({"probeset_name": data_.get("probeset_name")})
+ diff_data.update({"author": author})
+ diff_data.update({"resource_id": request.args.get('resource-id')})
+ diff_data.update({"timestamp": datetime.datetime.now().strftime(
+ "%Y-%m-%d %H:%M:%S")})
+ insert(conn,
+ table="metadata_audit",
+ data=MetadataAudit(dataset_id=data_.get("id"),
+ editor=author.decode("utf-8"),
+ json_data=json.dumps(diff_data)))
+ return redirect(f"/datasets/traits/{name}"
+ f"?resource-id={request.args.get('resource-id')}")
+
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 665aabb0..220d9b87 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -416,64 +416,6 @@ def submit_trait_form():
version=GN_VERSION)
-@app.route("/probeset/update", methods=["POST"])
-def update_probeset():
- 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"))
- data_ = request.form.to_dict()
- probeset_ = {
- "id_": data_.get("id"),
- "symbol": data_.get("symbol"),
- "description": data_.get("description"),
- "probe_target_description": data_.get("probe_target_description"),
- "chr_": data_.get("chr"),
- "mb": data_.get("mb"),
- "alias": data_.get("alias"),
- "geneid": data_.get("geneid"),
- "homologeneid": data_.get("homologeneid"),
- "unigeneid": data_.get("unigeneid"),
- "omim": data_.get("OMIM"),
- "refseq_transcriptid": data_.get("refseq_transcriptid"),
- "blatseq": data_.get("blatseq"),
- "targetseq": data_.get("targetseq"),
- "strand_probe": data_.get("Strand_Probe"),
- "probe_set_target_region": data_.get("probe_set_target_region"),
- "probe_set_specificity": data_.get("probe_set_specificity"),
- "probe_set_blat_score": data_.get("probe_set_blat_score"),
- "probe_set_blat_mb_start": data_.get("probe_set_blat_mb_start"),
- "probe_set_blat_mb_end": data_.get("probe_set_blat_mb_end"),
- "probe_set_strand": data_.get("probe_set_strand"),
- "probe_set_note_by_rw": data_.get("probe_set_note_by_rw"),
- "flag": data_.get("flag")
- }
- updated_probeset = update(
- conn, "ProbeSet",
- data=Probeset(**probeset_),
- where=Probeset(id_=data_.get("id")))
-
- diff_data = {}
- author = (g.user_session.record.get(b"user_id",
- b"").decode("utf-8") or
- g.user_session.record.get("user_id", ""))
- if updated_probeset:
- diff_data.update({"Probeset": diff_from_dict(old={
- k: data_.get(f"old_{k}") for k, v in probeset_.items()
- if v is not None}, new=probeset_)})
- if diff_data:
- diff_data.update({"probeset_name": data_.get("probeset_name")})
- diff_data.update({"author": author.decode('utf-8')})
- diff_data.update({"timestamp": datetime.datetime.now().strftime(
- "%Y-%m-%d %H:%M:%S")})
- insert(conn,
- table="metadata_audit",
- data=MetadataAudit(dataset_id=data_.get("id"),
- editor=author.decode("utf-8"),
- json_data=json.dumps(diff_data)))
- return redirect(f"/trait/edit/probeset-name/{data_.get('probeset_name')}")
-
-
@app.route("/create_temp_trait", methods=('POST',))
def create_temp_trait():
logger.info(request.url)