修复说明reuse文件夹图片丢失问题
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,6 @@
|
||||
from io import BytesIO
|
||||
import copy
|
||||
from docx.parts.image import ImagePart
|
||||
from pathlib import Path
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
@@ -468,22 +471,53 @@ class UploadDocumentController(ControllerBase):
|
||||
fs.save(f"第{digit_to_chinese(round_num)}轮{documentType}.docx", self.upload_file)
|
||||
return ChenResponse(status=200, code=200, message=f'上传{documentType}成功!')
|
||||
|
||||
# 主功能函数:将所有大纲的片段储存在reuse下面,以便其他文件使用
|
||||
def get_dg_to_reuse_dir(self, reuse_dir_path: Path):
|
||||
"""将大纲的文档片段储存在/reuse文件夹下面"""
|
||||
doc = Document(self.upload_file)
|
||||
frag_list = self.get_document_frag_list(doc)
|
||||
"""将大纲的文档片段储存在/reuse文件夹下面(保留图片)"""
|
||||
src_doc = Document(self.upload_file)
|
||||
frag_list = self.get_document_frag_list(src_doc)
|
||||
|
||||
for frag_item in frag_list:
|
||||
# 目的是格式明确按照“测评大纲.docx”进行,后续文档一样必须按照这样
|
||||
if frag_item['content'] is None:
|
||||
continue
|
||||
|
||||
# 1. 创建目标文档(基于 basic_doc.docx 模板)
|
||||
new_doc = Document((reuse_dir_path / 'basic_doc.docx').as_posix())
|
||||
if frag_item['content'] is not None:
|
||||
# XML元素可以直接append
|
||||
new_doc.element.body.clear_content()
|
||||
for frag_child in frag_item['content'].iterchildren():
|
||||
new_doc.element.body.append(frag_child)
|
||||
|
||||
# 2. 逐元素复制 XML,并修复图片引用
|
||||
for child in frag_item['content'].iterchildren():
|
||||
self._copy_element_with_images(child, src_doc, new_doc)
|
||||
|
||||
# 3. 保存片段文件
|
||||
filename = f"{frag_item['alias']}.docx"
|
||||
new_doc.save((reuse_dir_path / filename).as_posix())
|
||||
|
||||
def _copy_element_with_images(self, element, src_doc, dst_doc):
|
||||
"""
|
||||
复制 lxml 元素及其子树,将源文档中的图片关系迁移至目标文档。
|
||||
"""
|
||||
# 1. 深拷贝元素
|
||||
new_element = copy.deepcopy(element)
|
||||
# 2. 使用本地名称匹配查找图片节点(完全避免命名空间前缀参数)
|
||||
pic_nodes = new_element.xpath('.//*[local-name()="pic"]')
|
||||
for pic in pic_nodes:
|
||||
blip_nodes = pic.xpath('.//*[local-name()="blip"]')
|
||||
for blip in blip_nodes:
|
||||
embed_attr = '{http://schemas.openxmlformats.org/officeDocument/2006/relationships}embed'
|
||||
old_rId = blip.get(embed_attr)
|
||||
if not old_rId:
|
||||
continue
|
||||
src_image_part = src_doc.part.related_parts.get(old_rId)
|
||||
if src_image_part is None or not isinstance(src_image_part, ImagePart):
|
||||
continue
|
||||
# 添加图片到目标文档,获取新 rId
|
||||
image_stream = BytesIO(src_image_part.blob)
|
||||
new_rId, _ = dst_doc.part.get_or_add_image(image_stream)
|
||||
# 更新属性
|
||||
blip.set(embed_attr, new_rId)
|
||||
# 3. 追加到目标文档 body
|
||||
dst_doc.element.body.append(new_element)
|
||||
|
||||
# 辅助函数:将上传文件的文档片段以列表形式返回
|
||||
def get_document_frag_list(self, doc: Document):
|
||||
body = doc.element.body
|
||||
|
||||
@@ -196,7 +196,11 @@ def generate_temp_doc(doc_type: str, project_id: int, round_num=None, frag_list=
|
||||
# 根据节点找到图片的关联id
|
||||
embed = img.xpath('.//a:blip/@r:embed')[0]
|
||||
# 这里得到ImagePart -> 马上要给新文档添加
|
||||
related_part: ImagePart = doc_copied.part.related_parts[embed]
|
||||
related_part: ImagePart = doc_copied.part.related_parts.get(embed)
|
||||
if related_part is None:
|
||||
# 可选:记录警告日志,便于排查哪些文档片段有问题
|
||||
print(f"警告: 文档片段 '{area_pop_name}' 中的图片引用 {embed} 未找到,已跳过!!!!")
|
||||
continue
|
||||
# doc_copied.part.related_parts是一个字典
|
||||
image_part_list.append({'name': area_pop_name, 'img': related_part})
|
||||
|
||||
|
||||
BIN
cdtestplant_v1/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
cdtestplant_v1/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
cdtestplant_v1/__pycache__/settings.cpython-314.pyc
Normal file
BIN
cdtestplant_v1/__pycache__/settings.cpython-314.pyc
Normal file
Binary file not shown.
BIN
conf/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
conf/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
conf/__pycache__/env.cpython-314.pyc
Normal file
BIN
conf/__pycache__/env.cpython-314.pyc
Normal file
Binary file not shown.
1422
dbdata.sql
Normal file
1422
dbdata.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -1,2 +0,0 @@
|
||||
[WARNING][2025-04-29 14:20:41,997][logger.py:25][回归测试记录模块][单个问题单表格]片段:问题单4未关联用例,请检查
|
||||
[WARNING][2026-01-20 16:34:34,986][logger.py:25][回归测试说明模块][当前文档全部片段]片段:该项目没有创建轮次
|
||||
|
||||
2107
logs/root_log
2107
logs/root_log
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
media/R2601/final_seitai/测评大纲.docx
Normal file
BIN
media/R2601/final_seitai/测评大纲.docx
Normal file
Binary file not shown.
BIN
media/R2601/final_seitai/测试记录.docx
Normal file
BIN
media/R2601/final_seitai/测试记录.docx
Normal file
Binary file not shown.
BIN
media/R2601/final_seitai/测试说明.docx
Normal file
BIN
media/R2601/final_seitai/测试说明.docx
Normal file
Binary file not shown.
BIN
media/R2601/final_seitai/问题单.docx
Normal file
BIN
media/R2601/final_seitai/问题单.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/temporary/研总需归追踪_temp.docx
Normal file
BIN
media/R2601/form_template/bg/temporary/研总需归追踪_temp.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/总体结论.docx
Normal file
BIN
media/R2601/form_template/bg/总体结论.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/技术依据文件.docx
Normal file
BIN
media/R2601/form_template/bg/技术依据文件.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/摸底清单.docx
Normal file
BIN
media/R2601/form_template/bg/摸底清单.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/测评完成情况.docx
Normal file
BIN
media/R2601/form_template/bg/测评完成情况.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/测评时间和地点.docx
Normal file
BIN
media/R2601/form_template/bg/测评时间和地点.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/测试内容和结果_第一轮次.docx
Normal file
BIN
media/R2601/form_template/bg/测试内容和结果_第一轮次.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/测试内容和结果_第二轮次.docx
Normal file
BIN
media/R2601/form_template/bg/测试内容和结果_第二轮次.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/测试有效性充分性说明.docx
Normal file
BIN
media/R2601/form_template/bg/测试有效性充分性说明.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/研总需归追踪.docx
Normal file
BIN
media/R2601/form_template/bg/研总需归追踪.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/综述.docx
Normal file
BIN
media/R2601/form_template/bg/综述.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/被测软件基本信息.docx
Normal file
BIN
media/R2601/form_template/bg/被测软件基本信息.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/软件质量评价.docx
Normal file
BIN
media/R2601/form_template/bg/软件质量评价.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/软件问题统计.docx
Normal file
BIN
media/R2601/form_template/bg/软件问题统计.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/问题汇总表.docx
Normal file
BIN
media/R2601/form_template/bg/问题汇总表.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/bg/需求指标符合性情况.docx
Normal file
BIN
media/R2601/form_template/bg/需求指标符合性情况.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/主要功能和性能指标.docx
Normal file
BIN
media/R2601/form_template/dg/主要功能和性能指标.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/主要战技指标.docx
Normal file
BIN
media/R2601/form_template/dg/主要战技指标.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/代码质量度量分析表.docx
Normal file
BIN
media/R2601/form_template/dg/代码质量度量分析表.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/动态测试环境说明.docx
Normal file
BIN
media/R2601/form_template/dg/动态测试环境说明.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/动态测试环境说明_2.docx
Normal file
BIN
media/R2601/form_template/dg/动态测试环境说明_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/动态硬件和固件项.docx
Normal file
BIN
media/R2601/form_template/dg/动态硬件和固件项.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/动态硬件和固件项_2.docx
Normal file
BIN
media/R2601/form_template/dg/动态硬件和固件项_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/动态软件项.docx
Normal file
BIN
media/R2601/form_template/dg/动态软件项.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/动态软件项_2.docx
Normal file
BIN
media/R2601/form_template/dg/动态软件项_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/反向需求规格追踪表.docx
Normal file
BIN
media/R2601/form_template/dg/反向需求规格追踪表.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/技术依据文件.docx
Normal file
BIN
media/R2601/form_template/dg/技术依据文件.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/标准依据文件.docx
Normal file
BIN
media/R2601/form_template/dg/标准依据文件.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评对象.docx
Normal file
BIN
media/R2601/form_template/dg/测评对象.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评对象_2.docx
Normal file
BIN
media/R2601/form_template/dg/测评对象_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评数据.docx
Normal file
BIN
media/R2601/form_template/dg/测评数据.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评数据_2.docx
Normal file
BIN
media/R2601/form_template/dg/测评数据_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评时间和地点.docx
Normal file
BIN
media/R2601/form_template/dg/测评时间和地点.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评条件保障.docx
Normal file
BIN
media/R2601/form_template/dg/测评条件保障.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测评组织及任务分工.docx
Normal file
BIN
media/R2601/form_template/dg/测评组织及任务分工.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测试内容充分性及测试方法有效性分析.docx
Normal file
BIN
media/R2601/form_template/dg/测试内容充分性及测试方法有效性分析.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测试策略.docx
Normal file
BIN
media/R2601/form_template/dg/测试策略.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测试级别和测试类型.docx
Normal file
BIN
media/R2601/form_template/dg/测试级别和测试类型.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/测试项及方法.docx
Normal file
BIN
media/R2601/form_template/dg/测试项及方法.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/环境差异性分析.docx
Normal file
BIN
media/R2601/form_template/dg/环境差异性分析.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/环境差异性分析_2.docx
Normal file
BIN
media/R2601/form_template/dg/环境差异性分析_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/研制总要求追踪表.docx
Normal file
BIN
media/R2601/form_template/dg/研制总要求追踪表.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/缩略语.docx
Normal file
BIN
media/R2601/form_template/dg/缩略语.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/联系人和方式.docx
Normal file
BIN
media/R2601/form_template/dg/联系人和方式.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/被测软件功能.docx
Normal file
BIN
media/R2601/form_template/dg/被测软件功能.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/被测软件基本信息.docx
Normal file
BIN
media/R2601/form_template/dg/被测软件基本信息.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/被测软件性能.docx
Normal file
BIN
media/R2601/form_template/dg/被测软件性能.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/被测软件接口.docx
Normal file
BIN
media/R2601/form_template/dg/被测软件接口.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/需求规格说明追踪表.docx
Normal file
BIN
media/R2601/form_template/dg/需求规格说明追踪表.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/静态测试环境说明.docx
Normal file
BIN
media/R2601/form_template/dg/静态测试环境说明.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/静态硬件和固件项.docx
Normal file
BIN
media/R2601/form_template/dg/静态硬件和固件项.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/静态硬件和固件项_2.docx
Normal file
BIN
media/R2601/form_template/dg/静态硬件和固件项_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/静态软件项.docx
Normal file
BIN
media/R2601/form_template/dg/静态软件项.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/静态软件项_2.docx
Normal file
BIN
media/R2601/form_template/dg/静态软件项_2.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/dg/顶层技术文件.docx
Normal file
BIN
media/R2601/form_template/dg/顶层技术文件.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/hjl/测试用例记录.docx
Normal file
BIN
media/R2601/form_template/hjl/测试用例记录.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/hjl/被测软件基本信息.docx
Normal file
BIN
media/R2601/form_template/hjl/被测软件基本信息.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/hsm/temporary/第三轮用例追踪_temp.docx
Normal file
BIN
media/R2601/form_template/hsm/temporary/第三轮用例追踪_temp.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/hsm/temporary/第二轮用例追踪_temp.docx
Normal file
BIN
media/R2601/form_template/hsm/temporary/第二轮用例追踪_temp.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/hsm/回归测试用例概述.docx
Normal file
BIN
media/R2601/form_template/hsm/回归测试用例概述.docx
Normal file
Binary file not shown.
BIN
media/R2601/form_template/hsm/回归测试需求.docx
Normal file
BIN
media/R2601/form_template/hsm/回归测试需求.docx
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user