refactor: P3a 模型层迁入 src/modules/(22 模型)

- 19 个模块目录(system/association/cms/dictionary/configuration/log 等)
- 一对一 16 个 + 合并 3 组(dict+dict_item、config+config_item、login_log+operation_log)
- 重写模型 import:base_db/base_model→src.common、db→src.core.database、
  case_converter/rich_text/request→src.common.utils
- application/models/ 全部替换为 shim(指向 src.modules)
- src/models_registry.py 改为从 src.modules 全量导入

【修复】codemod 两处 bug:shim 与 registry 的 import 路径含斜杠(已改点分);
strip_license 误剥无许可头文件的 docstring 开头(log/models.py 已补回)

【验收】22 表全量识别;应用启动;pytest 5 passed

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DjangoAdmin Dev
2026-08-07 13:48:30 +08:00
co-authored by Claude
parent 658ee6d596
commit 6de4f3bef2
64 changed files with 3126 additions and 3399 deletions
+4 -197
View File
@@ -1,201 +1,8 @@
"""
登录日志模型模块
兼容 shim(绞杀者迁移期间保留)
=============================================================
提供登录日志管理的数据模型定义,用于记录用户登录、退出等操作日志。
模型已迁移至 src.modules.log.models。
本文件仅作兼容转发,最终在 P7(切尾)阶段删除。
"""
from application.models.base_db import BaseDB
from application.models.base_model import BaseModel
from config import DB_PREFIX
from extensions import db
from utils.case_converter import convert_camel_to_snake
# ============================================================
# 登录日志模型
# ============================================================
class LoginLog(BaseModel, BaseDB):
"""
登录日志模型
用于记录用户登录和退出操作的详细信息,包括:登录账号、日志类型、
来源、请求信息、IP地址、归属地、设备信息、请求耗时、操作状态等。
Attributes:
id: 主键ID(继承自 BaseModel)
username: 登录账号(String(50),必填)
log_type: 日志类型(Integer,1-登录,2-退出,必填)
source: 登录来源(Integer,0-后台,1-前台,必填)
method: 请求方法(String(10),必填)
request_method: 请求方式(String(255),必填)
url: 请求URL(String(500),必填)
param: 请求参数(Text,可选)
result: 返回结果(Text,必填)
ip: IP地址(String(50),必填)
location: IP归属地(String(100),必填)
os: 操作系统(String(100),必填)
browser: 浏览器(String(100),必填)
consume_time: 请求耗时(Integer,必填)
status: 操作状态(Integer,0-正常,1-异常,必填)
error: 错误信息(Text,可选)
"""
# ============================================================
# 表配置
# ============================================================
# 设置表名
__tablename__ = DB_PREFIX + "login_log"
# ============================================================
# 字段定义
# ============================================================
# 登录账号
username = db.Column(
db.String(50),
nullable=False,
comment="登录账号"
)
# 日志类型:1-登录,2-退出
log_type = db.Column(
db.Integer,
nullable=False,
comment="日志类型:1-登录,2-退出"
)
# 登录来源:0-后台,1-前台
source = db.Column(
db.Integer,
nullable=False,
comment="登录来源:0-后台,1-前台"
)
# 请求方法(HTTP方法,如POST/GET)
method = db.Column(
db.String(10),
nullable=False,
comment="请求方法"
)
# 请求方式(视图方法路径,如application.views.login.logout)
request_method = db.Column(
db.String(255),
nullable=False,
comment="请求方式"
)
# 请求URL
url = db.Column(
db.String(500),
nullable=False,
comment="请求URL"
)
# 请求参数
param = db.Column(
db.Text,
nullable=True,
comment="请求参数"
)
# 返回结果
result = db.Column(
db.Text,
nullable=False,
comment="返回结果"
)
# IP地址
ip = db.Column(
db.String(50),
nullable=False,
comment="IP地址"
)
# IP归属地
location = db.Column(
db.String(100),
nullable=False,
comment="IP归属地"
)
# 操作系统
os = db.Column(
db.String(100),
nullable=False,
comment="操作系统"
)
# 浏览器
browser = db.Column(
db.String(100),
nullable=False,
comment="浏览器"
)
# 请求耗时(毫秒)
consume_time = db.Column(
db.Integer,
nullable=False,
comment="请求耗时"
)
# 操作状态:0-正常,1-异常
status = db.Column(
db.Integer,
nullable=False,
comment="操作状态:0-正常,1-异常"
)
# 错误信息
error = db.Column(
db.Text,
nullable=True,
comment="错误信息"
)
# ============================================================
# 常量定义
# ============================================================
class LogType:
"""日志类型常量"""
LOGIN = 1 # 登录
LOGOUT = 2 # 退出
class Source:
"""登录来源常量"""
ADMIN = 0 # 后台
FRONT = 1 # 前台
class Status:
"""操作状态常量"""
NORMAL = 0 # 正常
ERROR = 1 # 异常
# ============================================================
# 魔法方法
# ============================================================
def __repr__(self):
"""
返回模型的字符串表示
Returns:
str: 格式为 "登录日志:{username} - {log_type}" 的字符串
"""
log_type_name = "登录" if self.log_type == self.LogType.LOGIN else "退出"
return '登录日志:{} - {}'.format(self.username, log_type_name)
def __str__(self):
"""
返回模型的字符串表示
Returns:
str: 格式为 "登录日志:{username} - {log_type}" 的字符串
"""
return self.__repr__()
from src.modules.log.models import * # noqa: F401,F403