2023-01-29 22:28:27 +08:00
|
|
|
# The Mia! Accounting Flask Project.
|
|
|
|
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/1/25
|
|
|
|
|
|
|
|
# Copyright (c) 2023 imacat.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
"""The accounting application.
|
|
|
|
|
|
|
|
"""
|
|
|
|
import typing as t
|
|
|
|
|
|
|
|
from flask import Flask, Blueprint
|
|
|
|
|
2023-02-01 22:05:12 +08:00
|
|
|
from accounting.utils.user import AbstractUserUtils
|
2023-02-01 15:37:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
def init_app(app: Flask, user_utils: AbstractUserUtils,
|
|
|
|
url_prefix: str = "/accounting",
|
2023-01-29 22:28:27 +08:00
|
|
|
can_view_func: t.Callable[[], bool] | None = None,
|
|
|
|
can_edit_func: t.Callable[[], bool] | None = None) -> None:
|
|
|
|
"""Initialize the application.
|
|
|
|
|
|
|
|
:param app: The Flask application.
|
2023-02-01 15:37:56 +08:00
|
|
|
:param user_utils: The user utilities.
|
2023-01-29 22:28:27 +08:00
|
|
|
:param url_prefix: The URL prefix of the accounting application.
|
|
|
|
:param can_view_func: A callback that returns whether the current user can
|
|
|
|
view the accounting data.
|
|
|
|
:param can_edit_func: A callback that returns whether the current user can
|
|
|
|
edit the accounting data.
|
|
|
|
:return: None.
|
|
|
|
"""
|
|
|
|
# The database instance must be set before loading everything
|
|
|
|
# in the application.
|
|
|
|
from .database import set_db
|
2023-02-01 22:05:12 +08:00
|
|
|
set_db(app.extensions["sqlalchemy"])
|
|
|
|
from .utils.user import init_user_utils
|
|
|
|
init_user_utils(user_utils)
|
2023-01-29 22:28:27 +08:00
|
|
|
|
|
|
|
bp: Blueprint = Blueprint("accounting", __name__,
|
|
|
|
url_prefix=url_prefix,
|
|
|
|
template_folder="templates",
|
|
|
|
static_folder="static")
|
|
|
|
|
|
|
|
from . import locale
|
|
|
|
locale.init_app(app, bp)
|
|
|
|
|
|
|
|
from .utils import permission
|
|
|
|
permission.init_app(app, can_view_func, can_edit_func)
|
|
|
|
|
|
|
|
from . import base_account
|
|
|
|
base_account.init_app(app, bp)
|
|
|
|
|
2023-02-01 15:37:56 +08:00
|
|
|
from . import account
|
|
|
|
account.init_app(app, bp)
|
|
|
|
|
2023-02-01 16:30:02 +08:00
|
|
|
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")
|
|
|
|
|
2023-01-29 22:28:27 +08:00
|
|
|
app.register_blueprint(bp)
|