diff --git a/src/accounting/__init__.py b/src/accounting/__init__.py index edca8b5..4c0cc09 100644 --- a/src/accounting/__init__.py +++ b/src/accounting/__init__.py @@ -106,4 +106,9 @@ def init_app(app: Flask, user_utils: AbstractUserUtils, from . import account account.init_app(app, bp) + from .utils.next_url import append_next, inherit_next, or_next + bp.add_app_template_filter(append_next, "append_next") + bp.add_app_template_filter(inherit_next, "inherit_next") + bp.add_app_template_filter(or_next, "or_next") + app.register_blueprint(bp) diff --git a/src/accounting/account/views.py b/src/accounting/account/views.py index e4215db..aa4f0d9 100644 --- a/src/accounting/account/views.py +++ b/src/accounting/account/views.py @@ -26,6 +26,7 @@ from werkzeug.datastructures import ImmutableMultiDict from accounting.database import db from accounting.locale import lazy_gettext from accounting.models import Account, BaseAccount +from accounting.utils.next_url import inherit_next, or_next from accounting.utils.pagination import Pagination from accounting.utils.permission import can_view, has_permission, can_edit from .forms import AccountForm, sort_accounts_in @@ -79,13 +80,14 @@ def add_account() -> redirect: for error in form.errors[key]: flash(error, "error") session["form"] = urlencode(list(request.form.items())) - return redirect(url_for("accounting.account.create")) + return redirect(inherit_next(url_for("accounting.account.create"))) account: Account = Account() form.populate_obj(account) db.session.add(account) db.session.commit() flash(lazy_gettext("The account is added successfully"), "success") - return redirect(url_for("accounting.account.detail", account=account)) + return redirect(inherit_next(url_for("accounting.account.detail", + account=account))) @bp.get("/", endpoint="detail") @@ -130,16 +132,19 @@ def update_account(account: Account) -> redirect: for error in form.errors[key]: flash(error, "error") session["form"] = urlencode(list(request.form.items())) - return redirect(url_for("accounting.account.edit", account=account)) + return redirect(inherit_next(url_for("accounting.account.edit", + account=account))) with db.session.no_autoflush: form.populate_obj(account) if not db.session.is_modified(account): flash(lazy_gettext("The account was not modified."), "success") - return redirect(url_for("accounting.account.detail", account=account)) + return redirect(inherit_next(url_for("accounting.account.detail", + account=account))) form.post_update(account) db.session.commit() flash(lazy_gettext("The account is updated successfully."), "success") - return redirect(url_for("accounting.account.detail", account=account)) + return redirect(inherit_next(url_for("accounting.account.detail", + account=account))) @bp.post("//delete", endpoint="delete") @@ -156,4 +161,4 @@ def delete_account(account: Account) -> redirect: sort_accounts_in(account.base_code, account.id) db.session.commit() flash(lazy_gettext("The account is deleted successfully."), "success") - return redirect(url_for("accounting.account.list")) + return redirect(or_next(url_for("accounting.account.list"))) diff --git a/src/accounting/templates/accounting/account/detail.html b/src/accounting/templates/accounting/account/detail.html index 4e8aa4f..49a90f5 100644 --- a/src/accounting/templates/accounting/account/detail.html +++ b/src/accounting/templates/accounting/account/detail.html @@ -26,12 +26,12 @@ First written: 2023/1/31 {% block content %}
- + {{ A_("Back") }} {% if can_edit_accounting() %} - + {{ A_("Settings") }} @@ -44,7 +44,7 @@ First written: 2023/1/31 {% if can_edit_accounting() %} @@ -53,6 +53,9 @@ First written: 2023/1/31 {% if can_edit_accounting() %}
+ {% if "next" in request.args %} + + {% endif %}