From 9ad492d03acbb30b5c6d67d98c55bf7bc878e00e Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Mon, 8 Aug 2022 12:34:38 +0300 Subject: Remove "diff" logic from edit_probeset * wqflask/wqflask/metadata_edits.py (edit_probeset): Delete logic for fetching diff. Move that... (show_history): ... here * wqflask/wqflask/templates/edit_probeset.html: Update template to show diffs in a history.html. Reposition and rename the h1 tag of this page. --- wqflask/wqflask/metadata_edits.py | 69 ++++++++++------------------ wqflask/wqflask/templates/edit_probeset.html | 9 ++-- 2 files changed, 29 insertions(+), 49 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index 4b960072..0840d4dd 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -127,40 +127,7 @@ def edit_probeset(conn, name): columns=list(probeset_mapping.values()), where=Probeset(name=name), ) - json_data = fetchall( - conn, "metadata_audit", where=MetadataAudit(dataset_id=probeset_.id_) - ) - Edit = namedtuple("Edit", ["field", "old", "new", "diff"]) - Diff = namedtuple("Diff", ["author", "diff", "timestamp"]) - diff_data = [] - for data in json_data: - json_ = json.loads(data.json_data) - timestamp = json_.get("timestamp") - author = json_.get("author") - for key, value in json_.items(): - if isinstance(value, dict): - for field, data_ in value.items(): - diff_data.append( - Diff( - author=author, - diff=Edit( - field, - data_.get("old"), - data_.get("new"), - "\n".join( - difflib.ndiff( - [data_.get("old")], [data_.get("new")] - ) - ), - ), - timestamp=timestamp, - ) - ) - diff_data_ = None - if len(diff_data) > 0: - diff_data_ = groupby(diff_data, lambda x: x.timestamp) return { - "diff": diff_data_, "probeset": probeset_, } @@ -554,21 +521,31 @@ def show_diff(name): @metadata_edit.route("//traits//history") -def show_history(dataset_id: str, name: str): +@metadata_edit.route("/probeset/") +def show_history(dataset_id: str = "", name: str = ""): diff_data_ = None with database_connection() as conn: - publish_xref = fetchone( - conn=conn, - table="PublishXRef", - where=PublishXRef(id_=name, inbred_set_id=dataset_id), - ) - - json_data = fetchall( - conn, - "metadata_audit", - where=MetadataAudit(dataset_id=publish_xref.id_), - ) - + json_data = None + if dataset_id: # This is a published phenotype + json_data = fetchall( + conn, + "metadata_audit", + where=MetadataAudit(dataset_id=fetchone( + conn=conn, + table="PublishXRef", + where=PublishXRef(id_=name, inbred_set_id=dataset_id), + ).id_), + ) + else: # This is a probeset + json_data = fetchall( + conn, "metadata_audit", + where=MetadataAudit(dataset_id=fetchone( + conn=conn, + table="ProbeSet", + columns=list(probeset_mapping.values()), + where=Probeset(name=name), + ).id_) + ) Edit = namedtuple("Edit", ["field", "old", "new", "diff"]) Diff = namedtuple("Diff", ["author", "diff", "timestamp"]) diff_data = [] diff --git a/wqflask/wqflask/templates/edit_probeset.html b/wqflask/wqflask/templates/edit_probeset.html index ab91b701..d9aee9d8 100644 --- a/wqflask/wqflask/templates/edit_probeset.html +++ b/wqflask/wqflask/templates/edit_probeset.html @@ -2,8 +2,12 @@ {% block title %}Trait Submission{% endblock %} {% block content %} -Edit Trait for Probeset -Submit Trait | Reset +
+ +
{% if diff %} @@ -54,7 +58,6 @@ Submit Trait | Reset {% endif %}
-

Probeset Information:

-- cgit v1.2.3