feat: 支持会话内补传资料并保持绑定
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
from django import forms
|
||||
from pathlib import Path
|
||||
|
||||
from apps.documents.forms import MultipleFileField, SUPPORTED_EXTENSIONS
|
||||
|
||||
|
||||
class ChatForm(forms.Form):
|
||||
@@ -38,3 +41,23 @@ class ChatForm(forms.Form):
|
||||
def clean_document_ids(self):
|
||||
# View 与 Agent Core 都使用整型文档 ID,统一在表单层完成转换。
|
||||
return [int(document_id) for document_id in self.cleaned_data.get("document_ids", [])]
|
||||
|
||||
|
||||
class ConversationUploadForm(forms.Form):
|
||||
# 会话右侧上传区只负责继续补传资料,不修改会话绑定关系。
|
||||
files = MultipleFileField(label="补充文件或资料包", required=False)
|
||||
file = forms.FileField(label="兼容单文件上传", required=False)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
files = list(cleaned_data.get("files") or [])
|
||||
file = cleaned_data.get("file")
|
||||
if file:
|
||||
files.append(file)
|
||||
if not files:
|
||||
raise forms.ValidationError("请至少上传一个文件或资料包。")
|
||||
for uploaded_file in files:
|
||||
if Path(uploaded_file.name).suffix.lower() not in SUPPORTED_EXTENSIONS:
|
||||
raise forms.ValidationError("仅支持 .txt、.md、.pdf、.docx、.zip 和 .7z 文件")
|
||||
cleaned_data["uploaded_files"] = files
|
||||
return cleaned_data
|
||||
|
||||
Reference in New Issue
Block a user