aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2022-05-19 10:52:02 +0300
committerBonfaceKilz2022-05-27 15:17:52 +0300
commitc8c298203841b88ee70cdd1dc3eba4426ca41e7b (patch)
tree4425e1328a42fd50dff7b9141813a090906456db /wqflask
parent6630b4892ae3ab6e211a0a1699ce66583e54796a (diff)
downloadgenenetwork2-c8c298203841b88ee70cdd1dc3eba4426ca41e7b.tar.gz
Store the data in SQL instead of Redis
* wqflask/wqflask/metadata_edits.py (show_case_attribute_columns): Store the diff data on a POST in SQL.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/metadata_edits.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index d38c34c4..de13159d 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -741,18 +741,26 @@ def show_case_attribute_columns():
@edit_admins_access_required
@login_required
def update_case_attributes():
- data_ = request.form.to_dict()
+ data_ = request.form.to_dict().get("data")
if data_:
- data_ = json.loads(data_.get("data"))
- data_["author"] = g.user_session.record.get("user_id")
- data_["timestamp"] = (datetime
- .datetime.now()
- .strftime("%Y-%m-%d %H:%M:%S"))
- # Save data to redis as a set
- redis_conn = redis.from_url(
- current_app.config["REDIS_URL"], decode_responses=True
+ author = (
+ (g.user_session.record.get(b"user_id") or b"").decode("utf-8")
+ or g.user_session.record.get("user_id")
+ or ""
)
- redis_conn.hset("case-attr-diffs:review",
- f"{data_.get('timestamp')}",
- json.dumps(data_))
+ with database_connection() as conn:
+ try:
+ with conn.cursor() as cursor:
+ cursor.execute(
+ "INSERT INTO caseattributes_audit "
+ "(status, editor, json_diff_data) "
+ "VALUES (%s, %s, %s)",
+ ('review', author, data_),
+ )
+ 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"))