diff options
-rw-r--r-- | wqflask/wqflask/metadata_edits.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index 101e6949..1a4d6f8d 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -806,3 +806,70 @@ def reject_case_attribute_data(): conn.commit() return redirect(url_for("metadata_edit.show_case_attribute_columns")) + + +@metadata_edit.route("/case-attributes/approve", methods=["POST", ]) +@case_attributes_edit_access +def approve_case_attribute_data(): + case_attr_id = request.form.to_dict().get("id") + with database_connection() as conn: + with conn.cursor() as cursor: + cursor.execute( + "SELECT json_diff_data FROM caseattributes_audit " + "WHERE id = %s", (case_attr_id,) + ) + diff_data = cursor.fetchone() + if diff_data: + diff_data = json.loads(diff_data[0]) + try: + # Insert (Most Important) + if diff_data.get("Insert"): + data = diff_data.get("Insert") + cursor.execute( + "INSERT INTO CaseAttribute " + "(Name, Description) VALUES " + "(%s, %s)", + (data.get("name"), data.get("description"),)) + cursor.execute( + "UPDATE caseattributes_audit SET " + "status = 'approved' WHERE id = %s", + (case_attr_id,)) + # Delete + elif diff_data.get("Deletion"): + data = diff_data.get("Deletion") + cursor.execute( + "DELETE FROM CaseAttribute " + "WHERE Id = %s", + (data.get("id"),)) + cursor.execute( + "UPDATE caseattributes_audit SET " + "status = 'approved' WHERE id = %s", + (case_attr_id,)) + # Modification + elif diff_data.get("Modification"): + data = diff_data.get("Modification") + if (desc_ := data.get("description")): + cursor.execute( + "UPDATE CaseAttribute SET " + "Description = %s WHERE Id = %s", + (desc_.get("Current"), diff_data.get("id"),) + ) + if (name_ := data.get("name")): + cursor.execute( + "UPDATE CaseAttribute SET " + "Name = %s WHERE Id = %s", + (name_.get("Current"), diff_data.get("id"),) + ) + if cursor.rowcount: + cursor.execute( + "UPDATE caseattributes_audit SET " + "status = 'approved' WHERE id = %s", + (case_attr_id,)) + except Exception as _e: + import MySQLdb + conn.rollback() + raise MySQLdb.Error(_e) from _e + conn.commit() + return redirect(url_for("metadata_edit.show_case_attribute_columns")) + + |