From f9cbfadca132f62eeca6c2eb10b7f02e05fb9a6b Mon Sep 17 00:00:00 2001 From: John Nduli Date: Thu, 29 Aug 2024 10:52:06 +0300 Subject: refactor: drop monad_requests and mark required fields --- gn2/wqflask/templates/wiki/edit_wiki.html | 6 +++--- gn2/wqflask/views.py | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'gn2/wqflask') diff --git a/gn2/wqflask/templates/wiki/edit_wiki.html b/gn2/wqflask/templates/wiki/edit_wiki.html index cee874a3..242456c4 100644 --- a/gn2/wqflask/templates/wiki/edit_wiki.html +++ b/gn2/wqflask/templates/wiki/edit_wiki.html @@ -25,7 +25,7 @@
- +
@@ -55,11 +55,11 @@
- +
- +
diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index b29efd94..93b7c958 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -1502,25 +1502,22 @@ def approve_reject_diff() -> Response: diff_id=form["diff_id"])) -@app.route("/wiki//edit", methods=["GET", "POST"]) +@app.route("/metadata/wiki//edit", methods=["GET", "POST"]) def edit_wiki(comment_id: int): """fetch generif metadata from gn3 and display it""" # FIXME: better error handling 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()) - ) + last_wiki_resp = requests.get(urljoin(GN3_LOCAL_URL, f"/api/metadata/wiki/{comment_id}")) + last_wiki_resp.raise_for_status() + last_wiki_content = last_wiki_resp.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())) - ) + species_dict_resp = requests.get(urljoin(GN3_LOCAL_URL, "/api/metadata/wiki/species")) + species_dict_resp.raise_for_status() + species_dict = species_dict_resp.json() + categories_resp = requests.get(urljoin(GN3_LOCAL_URL, "/api/metadata/wiki/categories")) + categories_resp.raise_for_status() + categories = list(categories_resp.json().keys()) grouped_categories = [categories[i : i + 3] for i in range(0, len(categories), 3)] return render_template( @@ -1542,6 +1539,9 @@ def edit_wiki(comment_id: int): "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()) + post_response = requests.post(urljoin(GN3_LOCAL_URL, f"api/metadata/wiki/{comment_id}/edit"), json=payload) + post_response.raise_for_status() + post_res = post_response.json() + flash(f"Success: {post_res}", "alert-success") return redirect(url_for("edit_wiki", comment_id=comment_id)) -- cgit v1.2.3