diff options
-rw-r--r-- | gn2/wqflask/templates/wiki/edit_wiki.html | 35 | ||||
-rw-r--r-- | gn2/wqflask/views.py | 61 |
2 files changed, 56 insertions, 40 deletions
diff --git a/gn2/wqflask/templates/wiki/edit_wiki.html b/gn2/wqflask/templates/wiki/edit_wiki.html index 942280dc..cee874a3 100644 --- a/gn2/wqflask/templates/wiki/edit_wiki.html +++ b/gn2/wqflask/templates/wiki/edit_wiki.html @@ -14,6 +14,7 @@ {% block content %} +{{ flash_me() }} <section class="container center-block"> <div class="row"> <div class="col-md-3"></div> @@ -30,18 +31,26 @@ <label for="species" class="col-sm-2">Species: </label> <select name="species" id="species"> {% for name, species_name in species_dict.items() %} - <option value="{{ name }}">{{ species_name }}</option> + {% if name == content["species"] %} + <option selected="selected" value="{{ name }}">{{ species_name }}</option> + {% else %} + <option value="{{ name }}">{{ species_name }}</option> + {% endif %} {% endfor %} </select> </div> <div class="form-group"> <label for="pubmed_ids" class="col-sm-2">PubMed IDS: </label> - <input type="text" name="pubmed_ids" size=25 maxlength=25> + <input type="text" name="pubmed_ids" size=25 maxlength=25 value="{{ " ".join(content["pubmed_ids"]) }}"> (optional, separate by blank space only) </div> <div class="form-group"> - <label for="weburl" class="col-sm-2">Web resource URL: </label> - <input type="text" name="weburl" value="http://" size=50 maxlength=255> + <label for="web_url" class="col-sm-2">Web resource URL: </label> + {% if content["weburl"] %} + <input type="text" name="web_url" value="{{ content["weburl"] }}" size=50 maxlength=255> + {% else %} + <input type="text" name="web_url" value="http://" size=50 maxlength=255> + {% endif %} (optional) </div> <div class="form-group"> @@ -64,7 +73,11 @@ <div class="row"> {% for cat in group %} <label class="checkbox-inline col-sm-3"> + {% if cat in content["categories"] %} + <input checked type="checkbox" name="genecategory" value="{{ cat }}"> {{ cat }} + {% else %} <input type="checkbox" name="genecategory" value="{{ cat }} "> {{ cat }} + {% endif %} </label> {% endfor %} </div> @@ -72,21 +85,9 @@ </div> <div class="form-group"> <button type="submit" name="submit" class="btn btn-primary">Update GeneWiki Entry</button> - <button type="reset" name="rest" class="btn btn-secondary">Reset</button> + <button type="reset" name="rest" class="btn btn-secondary" onClick="window.location.reload();">Reset</button> </div> </form> </div> </div> -<FORM METHOD="POST" ACTION="/webqtl/main.py" NAME="addgenerif"> - -<INPUT TYPE="hidden" NAME="symbol" VALUE="shh"> -<INPUT TYPE="hidden" NAME="curStatus" VALUE="insertCheck"> -<INPUT TYPE="hidden" NAME="FormID" VALUE="geneWiki"> -<INPUT TYPE="hidden" NAME="reason" VALUE=""> -<INPUT TYPE="hidden" NAME="action" VALUE="update"> -<INPUT TYPE="hidden" NAME="Id" VALUE="230"> -<P> - -</FORM> - {% endblock %} diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index 18f749c9..b29efd94 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -1502,31 +1502,46 @@ def approve_reject_diff() -> Response: diff_id=form["diff_id"])) -@app.route("/wiki/<int:comment_id>/edit") +@app.route("/wiki/<int:comment_id>/edit", methods=["GET", "POST"]) def edit_wiki(comment_id: int): """fetch generif metadata from gn3 and display it""" # FIXME: better error handling - last_wiki_content = ( - monad_requests.get(urljoin(GN3_LOCAL_URL, f"/api/metadata/wiki/{comment_id}")) - .then(lambda res: res) - .either(lambda _: [], lambda x: x.json()) - ) - species_dict = ( - monad_requests.get(urljoin(GN3_LOCAL_URL, "/api/metadata/wiki/species")) - .then(lambda res: res) - .either(lambda _: [], lambda x: x.json()) - ) - categories = ( - monad_requests.get(urljoin(GN3_LOCAL_URL, "/api/metadata/wiki/categories")) - .then(lambda resp: resp) - .either(lambda _: [], lambda x: list(x.json().keys())) - ) + if request.method == "GET": + last_wiki_content = ( + monad_requests.get(urljoin(GN3_LOCAL_URL, f"/api/metadata/wiki/{comment_id}")) + .either(lambda err: err.raise_for_status(), lambda x: x.json()) + ) + + species_dict = ( + monad_requests.get(urljoin(GN3_LOCAL_URL, "/api/metadata/wiki/species")) + .either(lambda err: err.raise_for_status(), lambda x: x.json()) + ) + categories = ( + monad_requests.get(urljoin(GN3_LOCAL_URL, "/api/metadata/wiki/categories")) + .either(lambda err: err.raise_for_status(), lambda x: list(x.json().keys())) + ) - grouped_categories = [categories[i : i + 3] for i in range(0, len(categories), 3)] + grouped_categories = [categories[i : i + 3] for i in range(0, len(categories), 3)] - return render_template( - "wiki/edit_wiki.html", - content=last_wiki_content, - species_dict=species_dict, - grouped_categories=grouped_categories, - ) + return render_template( + "wiki/edit_wiki.html", + content=last_wiki_content, + species_dict=species_dict, + grouped_categories=grouped_categories, + ) + if request.method == "POST": + post_data = request.form + payload = { + "symbol": post_data["symbol"], + "pubmed_ids": [x.strip() for x in post_data["pubmed_ids"].split()], + "species": post_data["species"], + "comment": post_data["comment"], + "email": post_data["email"], + "web_url": post_data["web_url"], + "initial": post_data["initial"], + "categories": post_data.getlist("genecategory"), + "reason": post_data["reason"], + } + post_res = monad_requests.post(urljoin(GN3_LOCAL_URL, f"api/metadata/wiki/{comment_id}/edit"), json=payload).either(lambda err: err.raise_for_status(), lambda success: success.json()) + flash(f"Success: {post_res}", "alert-success") + return redirect(url_for("edit_wiki", comment_id=comment_id)) |