From 13fe9b0db4734e8061c7badc4b4927c849e77283 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 19 May 2022 13:28:18 +0300 Subject: Fetch diff data from SQL * wqflask/wqflask/metadata_edits.py (show_case_attribute_columns): Replace the redis fetch with SQL for retrieving diff data. --- wqflask/wqflask/metadata_edits.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index de13159d..e08e945e 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -699,38 +699,42 @@ def approve_data(resource_id: str, file_name: str): @metadata_edit.route("/case-attributes") def show_case_attribute_columns(): - redis_conn = redis.from_url( - current_app.config["REDIS_URL"], decode_responses=True - ) - diff_data = redis_conn.hgetall("case-attr-diffs:review") + diff_data = None + with database_connection() as conn: + with conn.cursor() as cursor: + cursor.execute( + "SELECT editor, json_diff_data FROM " + "caseattributes_audit WHERE status = 'review'") + diff_data = cursor.fetchall() modifications, deletions, inserts = [], [], [] if diff_data: - for _, diff in diff_data.items(): + for author, diff in diff_data: diff = json.loads(diff) - if (m_ := diff.get("Modifications")): + diff["author"] = author + if (m_ := diff.get("Modification")): if m_.get("description"): m_["description"]["Diff"] = "\n".join( difflib.ndiff( [m_.get("description")["Original"]], [m_.get("description")["Current"]] - )) + )) if m_.get("name"): m_["name"]["Diff"] = "\n".join( difflib.ndiff( [m_.get("name")["Original"]], [m_.get("name")["Current"]] - )) - modifications.append(m_) - if (d_ := diff.get("Deletions")): + )) + modifications.append(m_) + if (d_ := diff.get("Deletion")): deletions.append(d_) - if (i_ := diff.get("Insertions")): + if (i_ := diff.get("Insert")): inserts.append(i_) - # Inserts, Deletes + # import pudb; pu.db - with database_connection() as conn: + with database_connection() as cursor: return render_template( "case_attributes.html", - case_attributes=get_case_attributes(conn), + case_attributes=get_case_attributes(cursor), modifications=modifications, deletions=deletions, inserts=inserts -- cgit v1.2.3