From 090366926be0622e0fca864f15556cd67f399f19 Mon Sep 17 00:00:00 2001 From: Rachmadani Haryono Date: Thu, 13 Jan 2022 21:52:43 +0800 Subject: [PATCH] refactor(bukuserver.views): unify msg between log and flash --- bukuserver/views.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/bukuserver/views.py b/bukuserver/views.py index 92d2645a..9ed9173e 100644 --- a/bukuserver/views.py +++ b/bukuserver/views.py @@ -192,11 +192,9 @@ def create_model(self, form): ) except Exception as ex: if not self.handle_view_exception(ex): - flash( - gettext("Failed to create record. %(error)s", error=str(ex)), - "error", - ) - LOG.exception("Failed to create record.") + msg = "Failed to create record." + flash( gettext("%(msg)s %(error)s", msg=msg, error=str(ex)), "error", ) + LOG.exception(msg) return False else: self.after_model_change(form, model, True) @@ -208,11 +206,9 @@ def delete_model(self, model): res = self.bukudb.delete_rec(model.id) except Exception as ex: if not self.handle_view_exception(ex): - flash( - gettext("Failed to delete record. %(error)s", error=str(ex)), - "error", - ) - LOG.exception("Failed to delete record.") + msg = "Failed to delete record." + flash( gettext("%(msg)s %(error)s", msg=msg, error=str(ex)), "error", ) + LOG.exception(msg) return False else: self.after_model_delete(model) @@ -416,11 +412,9 @@ def update_model(self, form: forms.BookmarkForm, model: Namespace): ) except Exception as ex: if not self.handle_view_exception(ex): - flash( - gettext("Failed to update record. %(error)s", error=str(ex)), - "error", - ) - LOG.exception("Failed to update record.") + msg = "Failed to update record." + flash( gettext("%(msg)s %(error)s", msg=msg, error=str(ex)), "error", ) + LOG.exception(msg) return False else: self.after_model_change(form, model, False) @@ -568,11 +562,9 @@ def delete_model(self, model): res = self.bukudb.delete_tag_at_index(0, model.name, chatty=False) except Exception as ex: if not self.handle_view_exception(ex): - flash( - gettext("Failed to delete record. %(error)s", error=str(ex)), - "error", - ) - LOG.exception("Failed to delete record.") + msg = "Failed to delete record." + flash( gettext("%(msg)s %(error)s", msg=msg, error=str(ex)), "error", ) + LOG.exception(msg) return False else: self.after_model_delete(model) @@ -587,11 +579,9 @@ def update_model(self, form, model): res = self.bukudb.replace_tag(original_name, [model.name]) except Exception as ex: if not self.handle_view_exception(ex): - flash( - gettext("Failed to update record. %(error)s", error=str(ex)), - "error", - ) - LOG.exception("Failed to update record.") + msg = "Failed to update record." + flash( gettext("%(msg)s %(error)s", msg=msg, error=str(ex)), "error", ) + LOG.exception(msg) return False else: self.after_model_change(form, model, False)