aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
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'))