feat(training): 完善安全培训题库与考试交互
修复 PDF 导入判断和填空题解析,支持文本题判分、回顾改答及安全培训三级流程校验。
This commit is contained in:
1 parent
ec4ed9b67d
commit
e62e4961d4
19 files changed
+721
-48
No files matched your search
@@ -103,6 +103,23 @@ def list_document_versions(document_id: int) -> list[KbDocumentVersion]:
|
||||
return list(document.versions)
|
||||
|
||||
|
||||
def resolve_training_preview_file_path(version_id: int) -> tuple[Path, str]:
|
||||
"""
|
||||
解析培训资料的可预览文件路径。
|
||||
|
||||
用途:培训配置的资料预览优先返回上传原件;部署环境未保留原件时,回退到清洗后预览文件,避免学习流程因历史文件缺失中断。
|
||||
参数与输出约束:仅接受有效且未删除的知识库版本;返回存在的绝对路径及下载展示名,不存在任何可用文件时抛出 NotFoundError。
|
||||
"""
|
||||
version = load_document_version(version_id)
|
||||
candidate_paths = (version.source_file_path, version.cleaned_preview_path, version.cleaned_file_path)
|
||||
for candidate in candidate_paths:
|
||||
preview_path = resolve_storage_path(candidate)
|
||||
if preview_path and preview_path.exists() and preview_path.is_file():
|
||||
filename = version.source_file_name or preview_path.name
|
||||
return preview_path, filename
|
||||
raise NotFoundError('培训资料文件不存在或已被移除')
|
||||
|
||||
|
||||
def resolve_source_file_path(version_id: int) -> tuple[Path, str]:
|
||||
"""
|
||||
解析版本原始文件路径。
|
||||
|
||||
Reference in new issue
Block a user