aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2022-03-02 15:52:52 +0300
committerBonfaceKilz2022-03-12 15:33:01 +0300
commita94cf0a3e20aab26df7a2c4049bd9b7fe9bb38a7 (patch)
tree05a7bad29569708aaf7a4d860ccc5123cdd6dc58 /wqflask
parentf51287f155a95b5ec1824ebb1f402d044f47524e (diff)
downloadgenenetwork2-a94cf0a3e20aab26df7a2c4049bd9b7fe9bb38a7.tar.gz
Fix broken f-strings
* wqflask/wqflask/metadata_edits.py (approve_data): Update query strings.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/metadata_edits.py61
1 files changed, 60 insertions, 1 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 4bc2c194..d6ba2fff 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -543,5 +543,64 @@ def approve_data(resource_id:str, file_name: str):
flash(("Automatically rejecting this file since no "
"changes could be applied."), "warning")
- return redirect(url_for('metadata_edit.list_diffs'))
+ n_deletions = 0
+ for deletion in (deletions := [d for d in sample_data.get("Deletions")]):
+ strain_name, _, _, _ = deletion.split(",")
+ __deletions, _, _ = delete_sample_data(
+ conn=conn,
+ trait_name=sample_data.get("trait_name"),
+ strain_name=strain_name,
+ phenotype_id=int(sample_data.get("phenotype_id")))
+ if __deletions:
+ n_deletions += 1
+ # Remove any data that already exists from sample_data deletes
+ else:
+ sample_data.get("Deletions").remove(deletion)
+
+ n_insertions = 0
+ for insertion in (
+ insertions := [d for d in sample_data.get("Additions")]):
+ (strain_name,
+ value, se, count) = insertion.split(",")
+ __insertions, _, _ = insert_sample_data(
+ conn=conn,
+ trait_name=sample_data.get("trait_name"),
+ strain_name=strain_name,
+ phenotype_id=int(sample_data.get("phenotype_id")),
+ value=value,
+ error=se,
+ count=count)
+ if __insertions:
+ n_insertions += 1
+ # Remove any data that already exists from sample_data inserts
+ else:
+ sample_data.get("Additions").remove(insertion)
+ if any([sample_data.get("Additions"),
+ sample_data.get("Modifications"),
+ sample_data.get("Deletions")]):
+ insert(conn,
+ table="metadata_audit",
+ data=MetadataAudit(
+ dataset_id=sample_data.get("trait_name"),
+ editor=sample_data.get("author"),
+ json_data=json.dumps(sample_data)))
+ # Once data is approved, rename it!
+ os.rename(os.path.join(f"{TMPDIR}/sample-data/diffs", file_name),
+ os.path.join(f"{TMPDIR}/sample-data/diffs",
+ f"{file_name}.approved"))
+ message = ""
+ if n_deletions:
+ flash(f"# Deletions: {n_deletions}", "success")
+ if n_insertions:
+ flash(f"# Additions: {len(modifications)}", "success")
+ if len(modifications):
+ flash(f"# Modifications: {len(modifications)}", "success")
+ else: # Edge case where you need to automatically reject the file
+ os.rename(os.path.join(f"{TMPDIR}/sample-data/diffs", file_name),
+ os.path.join(f"{TMPDIR}/sample-data/diffs",
+ f"{file_name}.rejected"))
+ flash(("Automatically rejecting this file since no "
+ "changes could be applied."), "warning")
+
+ return redirect(url_for('metadata_edit.list_diffs'))