From b00a4e42e9f4b0b857c100812ea4d30b32f738cb Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 30 Aug 2023 09:28:58 +0300 Subject: Call utils to replace unnecessary functions. --- wqflask/wqflask/oauth2/request_utils.py | 4 +++- wqflask/wqflask/views.py | 17 +++++------------ 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( -- cgit v1.2.3