aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-30 09:28:58 +0300
committerFrederick Muriuki Muriithi2023-10-26 05:00:30 +0300
commitb00a4e42e9f4b0b857c100812ea4d30b32f738cb (patch)
treeede562b7f7d333f3c2c1c3c0cccbdf922af387e9
parentbb1c01340ab6e05d7e468ea0b40af43f1c52cc59 (diff)
downloadgenenetwork2-b00a4e42e9f4b0b857c100812ea4d30b32f738cb.tar.gz
Call utils to replace unnecessary functions.
-rw-r--r--wqflask/wqflask/oauth2/request_utils.py4
-rw-r--r--wqflask/wqflask/views.py17
2 files changed, 8 insertions, 13 deletions
diff --git a/wqflask/wqflask/oauth2/request_utils.py b/wqflask/wqflask/oauth2/request_utils.py
index 2f475337..7d2ec539 100644
--- a/wqflask/wqflask/oauth2/request_utils.py
+++ b/wqflask/wqflask/oauth2/request_utils.py
@@ -86,7 +86,9 @@ def flash_success(success):
def with_flash_error(response) -> Callable:
def __err__(err) -> Response:
error = process_error(err)
- flash(f"{error['error']}: {error['error_description']}", "alert-danger")
+ flash(f"{error['status_code']} {error['error']}: "
+ f"{error['error_description']}",
+ "alert-danger")
return response
return __err__
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 11328238..30d0f872 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -81,7 +81,7 @@ from wqflask.db_info import InfoPage
from wqflask.oauth2 import client
from wqflask.oauth2.client import no_token_get
-from wqflask.oauth2.request_utils import with_flash_error
+from wqflask.oauth2.request_utils import with_flash_error, with_flash_success
from utility import temp_data
from utility.tools import get_setting
@@ -1177,22 +1177,15 @@ def edit_case_attributes(inbredset_id: int) -> Response:
}
}
- 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))
+ edit_case_attributes_page = 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__)
+ with_flash_error(edit_case_attributes_page),
+ with_flash_success(edit_case_attributes_page))
def __fetch_strains__(inbredset_group):
return client.get(f"case-attribute/{inbredset_id}/strains").then(