Skip to content

Commit

Permalink
refactor(bukuserver.views): unify msg between log and flash
Browse files Browse the repository at this point in the history
  • Loading branch information
rachmadaniHaryono committed Jan 13, 2022
1 parent 4380537 commit 0903669
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions bukuserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 0903669

Please sign in to comment.