feat(training): 培训模块改造!
This commit is contained in:
1 parent
57652ae581
commit
5f713f2c0c
11 files changed
+226
-51
No files matched your search
@@ -35,11 +35,22 @@ def _default_training_version(training_type: str) -> str:
|
||||
返回培训类型对应的默认版本号。
|
||||
|
||||
Args:
|
||||
training_type: 培训类型。当前仅允许 onboarding / safety。
|
||||
training_type: 培训类型编码。
|
||||
Returns:
|
||||
默认培训版本字符串。
|
||||
"""
|
||||
return "safety-v1" if training_type == "safety" else "onboarding-v1"
|
||||
return f"{training_type}-v1"
|
||||
|
||||
|
||||
def _configured_training_types() -> set[str]:
|
||||
"""读取数据库中已配置的培训类型编码,供进度接口动态校验。"""
|
||||
from app.models import TrainingConfig
|
||||
|
||||
return {
|
||||
str(training_type).strip()
|
||||
for training_type in db.session.execute(select(TrainingConfig.training_type)).scalars()
|
||||
if str(training_type or "").strip()
|
||||
}
|
||||
|
||||
|
||||
def _normalize_training_type(value: Any) -> str:
|
||||
@@ -47,13 +58,14 @@ def _normalize_training_type(value: Any) -> str:
|
||||
校验并标准化培训类型。
|
||||
|
||||
Args:
|
||||
value: 前端上传的培训类型,允许空值回退为 onboarding。
|
||||
value: 前端上传的培训类型编码,允许空值回退为 onboarding。
|
||||
Returns:
|
||||
合法的培训类型字符串。
|
||||
已配置的培训类型编码。
|
||||
"""
|
||||
text = str(value or "onboarding").strip() or "onboarding"
|
||||
if text not in TRAINING_TYPES:
|
||||
raise ValidationError("training_type is invalid", details={"field": "training_type", "allowed": sorted(TRAINING_TYPES)})
|
||||
text = str(value or "onboarding").strip().lower() or "onboarding"
|
||||
allowed = TRAINING_TYPES | _configured_training_types()
|
||||
if text not in allowed:
|
||||
raise ValidationError("training_type is invalid", details={"field": "training_type", "allowed": sorted(allowed)})
|
||||
return text
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user