You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iTi-System/iti_system/module.py

73 lines
2.2 KiB
Python

from __future__ import annotations
from apiflask import APIBlueprint
from .extensions.sys_log import init_sys_log
class SystemModule:
name = "iti_system"
def init_app(self, app) -> None:
app.extensions["iti_system"] = self
app.config.setdefault("SYSLOG_MAX_BODY_CHARS", 2048)
app.config.setdefault("SYSLOG_ITEMS_SAMPLE", 5)
app.config.setdefault(
"PERMISSION_CONFIG",
{
"SUPER_ADMIN_ROLE": "ADMIN",
"DEFAULT_ERROR_MESSAGE": "无权访问!",
"DEFAULT_ERROR_CODE": 403,
"SKIP_SUPER_ADMIN_DEFAULT": True,
},
)
init_sys_log(app)
from .events import init_event_handlers
init_event_handlers(app)
def register_routes(self, app) -> None:
sys_bp = APIBlueprint("sys", __name__, url_prefix="/sys")
for import_path in (
"iti_system.routes.log:bp",
"iti_system.routes.user:bp",
"iti_system.routes.user_attribute:bp",
"iti_system.routes.role:bp",
"iti_system.routes.config:bp",
"iti_system.routes.dict:bp",
"iti_system.routes.menu:bp",
"iti_system.routes.dept:bp",
"iti_system.routes.file:bp",
):
_register_blueprint(sys_bp, import_path)
app.register_blueprint(sys_bp)
from .routes.auth import bp as auth_bp
from .routes.common import file_access_bp, upload_bp
app.register_blueprint(auth_bp)
app.register_blueprint(upload_bp)
app.register_blueprint(file_access_bp)
def register_commands(self, app) -> None:
from .cli import iti_system_cli
app.cli.add_command(iti_system_cli, "iti-system")
def register_permissions(self, app) -> None:
return None
def register_menu_seed(self, app) -> None:
return None
def create_system_module() -> SystemModule:
return SystemModule()
def _register_blueprint(parent_bp, import_path: str) -> None:
module_path, attr_name = import_path.rsplit(":", 1)
module = __import__(module_path, fromlist=[attr_name])
parent_bp.register_blueprint(getattr(module, attr_name))