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.

This commit is contained in:
依瑪貓 2023-02-07 17:10:03 +08:00
parent 699db20308
commit 8e524674a3
2 changed files with 14 additions and 5 deletions

View File

@ -66,9 +66,7 @@ def init_app(app: Flask, user_utils: AbstractUserUtils,
from . import currency from . import currency
currency.init_app(app, bp) currency.init_app(app, bp)
from .utils.next_url import append_next, inherit_next, or_next from .utils import next_url
bp.add_app_template_filter(append_next, "append_next") next_url.init_app(bp)
bp.add_app_template_filter(inherit_next, "inherit_next")
bp.add_app_template_filter(or_next, "or_next")
app.register_blueprint(bp) app.register_blueprint(bp)

View File

@ -22,7 +22,7 @@ This module should not import any other module from the application.
from urllib.parse import urlparse, parse_qsl, ParseResult, urlencode, \ from urllib.parse import urlparse, parse_qsl, ParseResult, urlencode, \
urlunparse urlunparse
from flask import request from flask import request, Blueprint
def append_next(uri: str) -> str: 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: list[str] = list(uri_p)
parts[4] = urlencode(params) parts[4] = urlencode(params)
return urlunparse(parts) 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")