aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-29 13:10:04 +0300
committerFrederick Muriuki Muriithi2023-10-26 05:00:30 +0300
commitbb1c01340ab6e05d7e468ea0b40af43f1c52cc59 (patch)
treec46430e2714b3a57d60d7b6123a5f8714b6944ea
parent2a5895a6c69df6c73edf8a8de52f1232132820ed (diff)
downloadgenenetwork2-bb1c01340ab6e05d7e468ea0b40af43f1c52cc59.tar.gz
Process data before sending to API
-rw-r--r--wqflask/wqflask/templates/edit_case_attributes.html4
-rw-r--r--wqflask/wqflask/views.py39
2 files changed, 39 insertions, 4 deletions
diff --git a/wqflask/wqflask/templates/edit_case_attributes.html b/wqflask/wqflask/templates/edit_case_attributes.html
index e3b6a715..a05ecd17 100644
--- a/wqflask/wqflask/templates/edit_case_attributes.html
+++ b/wqflask/wqflask/templates/edit_case_attributes.html
@@ -18,6 +18,8 @@
<div class="container">
<h1>{{inbredset_group.InbredSetName}}: Edit Case-Attributes</h1>
+ {{flash_me()}}
+
<h3>Instructions</h3>
<ul>
<li>
@@ -32,7 +34,7 @@
</li>
</ul>
- <form method="POST" action="#">
+ <form method="POST" action="{{url_for('edit_case_attributes', inbredset_id=inbredset_id)}}">
<div class="form-group" style="text-align: center; padding: 1em 0 0 0;">
<input type="submit" value="Submit" class="btn btn-primary" />
<input type="reset" value="Reset" class="btn btn-warning" />
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index eba9dedb..11328238 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -18,6 +18,8 @@ import traceback
import uuid
import xlsxwriter
+from functools import reduce
+
from zipfile import ZipFile
from zipfile import ZIP_DEFLATED
@@ -1155,12 +1157,42 @@ def get_genotype(name):
metadata=metadata,
)
-@app.route("/case-attribute/<int:inbredset_id>/edit")
+@app.route("/case-attribute/<int:inbredset_id>/edit", methods=["GET", "POST"])
def edit_case_attributes(inbredset_id: int) -> Response:
"""
Edit the case-attributes for InbredSet group identified by `inbredset_id`.
"""
- from wqflask.oauth2 import client
+ if request.method == "POST":
+ form = request.form
+ def __process_data__(acc, item):
+ _new, strain, calabel = tuple(val.strip() for val in item[0].split(":"))
+ old_row = acc.get(strain, {})
+ return {
+ **acc,
+ strain: {
+ **old_row, "case-attributes": {
+ **old_row.get("case-attributes", {}),
+ calabel: item[1]
+ }
+ }
+ }
+
+ def __edit_fail__(error):
+ err = process_error(error)
+ flash(f"{err['error']}: {err['error_description']}", "alert-danger")
+ return redirect(url_for(
+ "edit_case_attributes", inbredset_id=inbredset_id))
+
+ def __edit_success__(result):
+ flash({result["message"]}, "alert-success")
+ return redirect(url_for(
+ "edit_case_attributes", inbredset_id=inbredset_id))
+ return client.post(
+ f"case-attribute/{inbredset_id}/edit",
+ json={
+ "edit-data": reduce(__process_data__, form.items(), {})
+ }).either(
+ __edit_fail__, __edit_success__)
def __fetch_strains__(inbredset_group):
return client.get(f"case-attribute/{inbredset_id}/strains").then(
@@ -1180,4 +1212,5 @@ def edit_case_attributes(inbredset_id: int) -> Response:
__fetch_strains__).then(__fetch_names__).then(
__fetch_values__).either(
lambda err: err, ## TODO: Handle error better
- lambda values: render_template("edit_case_attributes.html", **values))
+ lambda values: render_template(
+ "edit_case_attributes.html", inbredset_id=inbredset_id, **values))