From 8e524674a3400aa97301c7abcd52500e929c3ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 7 Feb 2023 17:10:03 +0800 Subject: [PATCH] Added the init_app function to the "accounting.utils.next_url" module to initialize the template filters, and apply it to the init_app function of the accounting application. --- src/accounting/__init__.py | 6 ++---- src/accounting/utils/next_url.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/accounting/__init__.py b/src/accounting/__init__.py index 6f1d6a2..ce80f2c 100644 --- a/src/accounting/__init__.py +++ b/src/accounting/__init__.py @@ -66,9 +66,7 @@ def init_app(app: Flask, user_utils: AbstractUserUtils, from . import currency currency.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") + from .utils import next_url + next_url.init_app(bp) app.register_blueprint(bp) diff --git a/src/accounting/utils/next_url.py b/src/accounting/utils/next_url.py index 4f10112..fcd3a77 100644 --- a/src/accounting/utils/next_url.py +++ b/src/accounting/utils/next_url.py @@ -22,7 +22,7 @@ This module should not import any other module from the application. from urllib.parse import urlparse, parse_qsl, ParseResult, urlencode, \ urlunparse -from flask import request +from flask import request, Blueprint def append_next(uri: str) -> str: @@ -73,3 +73,14 @@ def __set_next(uri: str, next_uri: str) -> str: parts: list[str] = list(uri_p) parts[4] = urlencode(params) return urlunparse(parts) + + +def init_app(bp: Blueprint) -> None: + """Initializes the application. + + :param bp: The blueprint of the accounting application. + :return: None. + """ + 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")