From 368dd574093e6d67b55e4224447395aabdd9e4dc Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 20 May 2022 09:58:23 +0300 Subject: Parse author id into a human readable name * wqflask/wqflask/metadata_edits.py (_get_author): New function. (show_case_attribute_columns): Pass the author name and id---case-attribute---field into the template. * wqflask/wqflask/templates/case_attributes.html: Add an "author" column when displaying the modified/deleted/inserted data. Also, add the case-attribute's id as a data-id element. --- wqflask/wqflask/metadata_edits.py | 16 +++++++++++++++- wqflask/wqflask/templates/case_attributes.html | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index e08e945e..dc2019c7 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -51,6 +51,14 @@ from gn3.db.sample_data import get_case_attributes metadata_edit = Blueprint("metadata_edit", __name__) +def _get_author(author: str) -> str: + redis_conn = redis.from_url( + current_app.config["REDIS_URL"], decode_responses=True + ) + return json.loads(redis_conn.hget("users", author)).get( + "full_name", author) + + def _get_diffs( diff_dir: str, user_id: str, redis_conn: redis.Redis, gn_proxy_url: str ): @@ -710,8 +718,10 @@ def show_case_attribute_columns(): if diff_data: for author, diff in diff_data: diff = json.loads(diff) - diff["author"] = author + author = _get_author(author) if (m_ := diff.get("Modification")): + m_["author"] = author + m_["id"] = id_ if m_.get("description"): m_["description"]["Diff"] = "\n".join( difflib.ndiff( @@ -726,8 +736,12 @@ def show_case_attribute_columns(): )) modifications.append(m_) if (d_ := diff.get("Deletion")): + d_["author"] = author + d_["id"] = id_ deletions.append(d_) if (i_ := diff.get("Insert")): + i_["author"] = author + i_["id"] = id_ inserts.append(i_) # import pudb; pu.db diff --git a/wqflask/wqflask/templates/case_attributes.html b/wqflask/wqflask/templates/case_attributes.html index 0e11554a..4eaf5454 100644 --- a/wqflask/wqflask/templates/case_attributes.html +++ b/wqflask/wqflask/templates/case_attributes.html @@ -128,6 +128,7 @@

Modify Existing Case Attributes

+ @@ -135,7 +136,8 @@ {% for data in modifications %} {% set reject_url = "" %} {% set approve_url = "" %} - + + + + @@ -185,6 +189,7 @@ {% set approve_url = "" %} + + + @@ -218,9 +225,10 @@ {% for data in inserts %} {% set reject_url = "" %} {% set approve_url = "" %} - - - + + + +
Author Diff Action
{{ data.get('author') }} {% if data.get("name")%} Name:
@@ -173,9 +175,11 @@
Case AttributeAuthor Description Action
{{data.get("name")}} {{ data.get('author') }} {{data.get("description")}}
Case AttributeAuthor Description Action
{{data.get("name")}} {{data.get("description")}}
{{data.get("name")}}{{ data.get('author')}}{{data.get("description")}}