diff options
author | BonfaceKilz | 2022-05-12 16:50:50 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-05-27 15:17:52 +0300 |
commit | f51fd91a2d09ddf7cb8a17b92dae4dba0429f603 (patch) | |
tree | c15c4c4b6586b9703a647b3d462dfb8c6b9e6b98 | |
parent | d998a402feca4d609953aa9dd5e58b70ee21a33a (diff) | |
download | genenetwork2-f51fd91a2d09ddf7cb8a17b92dae4dba0429f603.tar.gz |
Save diffed data to redis (wip)
* wqflask/wqflask/metadata_edits.py
(show_case_attribute_columns): pass the diff'ed
data to the template
(update_case_attributes): New function. Parses
data from JS and saves it redis in
"case-attr-diffs:review"
* wqflask/wqflask/templates/case_attributes.html:
Make post request---to save the data to redis for
approval.
-rw-r--r-- | wqflask/wqflask/metadata_edits.py | 42 | ||||
-rw-r--r-- | wqflask/wqflask/templates/case_attributes.html | 14 |
2 files changed, 50 insertions, 6 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index 279e63ac..cc9ee9bd 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -699,8 +699,46 @@ def approve_data(resource_id: str, file_name: str): @metadata_edit.route("/case-attributes") def show_case_attribute_columns(): - case_attributes = {} + redis_conn = redis.from_url( + current_app.config["REDIS_URL"], decode_responses=True + ) + diff_data = redis_conn.hgetall("case-attr-diffs:review") + modifications, deletions, inserts = [], [], [] + if diff_data: + for _, diff in diff_data.items(): + diff = json.loads(diff) + if (m_ := diff.get("Modifications")): + modifications.append(m_) + if (d_ := diff.get("Deletions")): + deletions.append(d_) + if (i_ := diff.get("Insertions")): + inserts.append(i_) + # Inserts, Deletes + with database_connection() as conn: return render_template( - "case_attributes.html", case_attributes=get_case_attributes(conn) + "case_attributes.html", + case_attributes=get_case_attributes(conn), + modifications=modifications, + deletions=deletions, + inserts=inserts + ) + + +@metadata_edit.route("/case-attributes", methods=("POST",)) +def update_case_attributes(): + data_ = request.form.to_dict() + 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 ) + redis_conn.hset("case-attr-diffs:review", + f"{data_.get('timestamp')}", + json.dumps(data_)) + return redirect(url_for("metadata_edit.show_case_attribute_columns")) diff --git a/wqflask/wqflask/templates/case_attributes.html b/wqflask/wqflask/templates/case_attributes.html index 7b6af57d..7aa6ee73 100644 --- a/wqflask/wqflask/templates/case_attributes.html +++ b/wqflask/wqflask/templates/case_attributes.html @@ -113,8 +113,7 @@ </tr> {% endfor %} </tbody> - </table> - + </table> </div> {%endblock%} @@ -192,8 +191,15 @@ if (!Object.keys(diff).length == 0) { diff["id"] = $(this).parents("tr").data("id"); } - $.post('{{ url_for("metadata_edit.update_case_attributes") }}', - JSON.stringify(diff)); + $.ajax({ + type: "POST", + data: {"data": JSON.stringify(diff)}, + url: '{{ url_for("metadata_edit.update_case_attributes") }}', + /* contentType: "application/json", */ + success: function(data, status, xhr) { + location.reload(); + } + }); }); // Edit row on edit button click $(document).on("click", ".edit", function(){ |