From 0d144bd464c493dc53be38fe5129bfbdfa1a3b29 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Tue, 1 Jul 2025 11:18:33 +0300 Subject: Add function for viewing a single diff change. Signed-off-by: Munyoki Kilyungi --- gn3/api/case_attributes.py | 2 +- gn3/db/case_attributes.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'gn3') diff --git a/gn3/api/case_attributes.py b/gn3/api/case_attributes.py index b7f50ad..2f01202 100644 --- a/gn3/api/case_attributes.py +++ b/gn3/api/case_attributes.py @@ -17,7 +17,7 @@ from MySQLdb.cursors import DictCursor from gn3.db.case_attributes import ( CaseAttributeEdit, EditStatus, - queue_edit) + view_change, from authlib.integrations.flask_oauth2.errors import _HTTPException from flask import ( jsonify, diff --git a/gn3/db/case_attributes.py b/gn3/db/case_attributes.py index 48d77c7..4bdb654 100644 --- a/gn3/db/case_attributes.py +++ b/gn3/db/case_attributes.py @@ -144,6 +144,20 @@ def __fetch_case_attrs_changes__(cursor, change_ids: tuple) -> list: return results +def view_change(cursor, change_id: int) -> dict: + cursor.execute( + "SELECT json_diff_data " + "FROM caseattributes_audit " + "WHERE id = %s", + (change_id,) + ) + json_diff_data, _ = cursor.fetchone() + if json_diff_data: + json_diff_data = json.loads(json_diff_data) + return json_diff_data + return {} + + def get_changes(cursor, inbredset_id: int, directory: Path) -> dict: directory = f"{directory}/case-attributes/{inbredset_id}" if not os.path.exists(directory): -- cgit 1.4.1