代码拉取完成,页面将自动刷新
同步操作将从 BidingCC/码多多 全能知识库(Python 版) 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
import os
import importlib
from fastapi import FastAPI
from tortoise.contrib.fastapi import register_tortoise
__all__ = ["register_db"]
def __loading_db_configs():
""" Load Db configuration """
configs = {}
try:
package = importlib.import_module("config")
clz = getattr(package, "GlobalSetting", None)
if not clz:
return configs
obj = clz().dict()
db_config = obj.get("DATABASES", {})
if db_config.get("apps"):
for k, v in db_config.get("apps").items():
if v and v.get("models") and isinstance(v.get("models"), str):
db_config["apps"][k]["models"] = __loading_model_files(v.get("models"))
return db_config
except ModuleNotFoundError:
return configs
def __loading_model_files(path: str):
""" Load Db models """
root_path: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + os.sep
mode_path: str = root_path + path.replace(".", os.sep)
all_files = []
for root, dirs, filenames in os.walk(mode_path):
dirs[:] = [d for d in dirs if not d.startswith("__")]
path_parts = os.path.relpath(root, mode_path).split(os.sep)
path_parts = [p for p in path_parts if not p.startswith("__")]
file_base_path = ".".join(path_parts) if path_parts else ""
for filename in filenames:
if not filename.startswith("__"):
filename_without_ext = os.path.splitext(filename)[0]
if file_base_path and file_base_path.endswith("."):
file_base_path = file_base_path[:-1]
file_path = f"{file_base_path}.{filename_without_ext}" if file_base_path else filename_without_ext
if not (file_path.startswith(".") and file_path != "."):
all_files.append(path + "." + file_path)
return all_files
def register_db(app: FastAPI):
""" Connect Databases """
register_tortoise(
app,
config=__loading_db_configs(),
generate_schemas=False,
add_exception_handlers=False,
)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。