文档导出自定义模板
Requirements & Systems Portal 的文档导出向导是您从需求和 V&V 活动中直接生成可编辑 Microsoft Word *.docx文件。您可以使用预定义模板或上传自己的模板。该向导由 Python-Docx-Template 库驱动,而 Python-Docx-Template 库又利用了 Jinja 模板引擎。通过这对动态组合,您可以制作自定义模板。
Python-Docx 模板库
Python-Docx-Template 库是扩展 Python-Docx 库功能的强大工具。它集成了 Jinja 模板引擎,可在 Word 文件中生成动态内容。这意味着您可以使用变量、循环和条件,在文档中即时填充数据。从本质上讲,这就像是给 Word 文档加了一杯浓咖啡。
管理导出模板
需求与系统门户实例可用的模板列在 Export templates页面 » Settings » Export templates).
-
默认情况下,提供六个模板--三个用于需求文档导出,三个用于 V&V 活动文档导出。
-
要添加新的用户定义模板,请单击页面右上方的
按钮。在出现的 Add template窗口中,选择新模板是否需要应用于 Requirements或 V&V Activities使用 Applicable objects下拉菜单,然后使用 Select template区域选择模板文件。
单击对话框中的
按钮添加模板。它将显示在 Export templates页面的列表中,然后可用于文档导出。
-
可以下载任何模板的文件。为此,,单击所需模板列中的
按钮,然后选择要下载的模板。 Name按钮,然后选择 Download命令。根据个人浏览器设置,浏览器会自动将文件下载到预定义的位置,或者询问您将文件存储在硬盘上的位置。
-
用户定义的模板可以用新的模板文件覆盖。为此,请单击所需模板列中的
按钮,然后选择 Name按钮,然后从出现的菜单中选择 Overwrite Template命令。在打开的 Overwrite template窗口定义模板适用性并选择新文件。启用 I confirm I want to overwrite选项,然后单击
按钮完成该过程。
附录 - 需求导出模板的数据对象结构
以下是需求导出模板将从中获取信息的对象的基本结构。
Requirement Export Templates – Data Object Structure
{
"规格":[
{
"id":"number"、
"名称":"字符串"、
"description":"字符串"、
"要求":[
{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"、
理由": "RichText", "文本": "RichText"RichText"、
"图像":["图像"]、
"类型":"字符串"、
"验证方法":[{
"名称":"string"、
"文本":"string"、
"component_vms":[{
"name":"string"、
"closeout_reference":"字符串"
}]
}],
"specification_id":"number"、
"group_id":"编号"、
"适用条件":["字符串"]、
"content_type"(内容类型):{
"id":"string"(字符串
"名称":"字符串"
},
"状态":"字符串"、
"遵从":"字符串"、
"compliance_comment":"字符串"、
"标签":["字符串"]、
"父母":[{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"
}],
"儿童":[{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"
}],
"所有者":{
"user":{
"username":"string"、
"first_name":"string"、
"last_name":"字符串"、
"组":["字符串"]
},
"组":{
"名称":"字符串"、
"users":["字符串"]
}
},
"文件":[{
"名称":"string"、
"description":"字符串"、
"版本":"字符串"、
"is_reference": "布尔":"布尔"、
"标签":["字符串"]
}],
"自定义字段":[{
"字段":"string"、
"value": ["string"]
}],
"位置":"数字"、
"验证项已验证":"number"、
"verification_items_total": "number"、
"验证项目":[{
"status":"string"、
"component":"string"、
"标签":["字符串"]、
"活动":{
"名称":"string"(字符串
"验证方法":["字符串"]
},
"last_item_run":{
"状态":"string"、
"comment":"字符串"
}
}],
"linked_components":[{
"id":"number"、
"名称":"string"、
"description":"字符串"、
"值":[{
"id":"数字"、
"名称":"字符串"、
"值":"字符串"、
"公式":"字符串"
}],
"textvalis":[{
"id":"数字"、
"名称":"字符串"、
"文本":"字符串"
}],
"矩阵":[{
"id":"数字"、
"名称":"字符串"、
"值":"字符串"、
"公式":"字符串"
}],
"datevalis":[{
"id":"数字"、
"名称":"字符串"、
"日期":"字符串"
}],
"创建者":"字符串"、
"附件":[{
"名称":"string"、
"description":"字符串"、
"版本":"字符串"、
"is_reference": "布尔":"布尔"、
"标签":["字符串"]
}]
}]
}
],
"content_type":{
"id":"号码"、
"名称":"string"
}
}
],
"要求":[
{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"、
理由": "RichText", "文本": "RichText"RichText"、
"图像":["图像"]、
"类型":"字符串"、
"验证方法":[{
"名称":"string"、
"文本":"string"、
"component_vms":[{
"name":"string"、
"closeout_reference":"字符串"
}]
}],
"specification_id":"number"、
"group_id":"编号"、
"适用条件":["字符串"]、
"content_type"(内容类型):{
"id":"string"(字符串
"名称":"字符串"
},
"状态":"字符串"、
"遵从":"字符串"、
"compliance_comment":"字符串"、
"标签":["字符串"]、
"父母":[{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"
}],
"儿童":[{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"
}],
"所有者":{
"user":{
"username":"string"、
"first_name":"string"、
"last_name":"字符串"、
"组":["字符串"]
},
"组":{
"名称":"字符串"、
"users":["字符串"]
}
},
"文件":[{
"名称":"string"、
"description":"字符串"、
"版本":"字符串"、
"is_reference": "布尔":"布尔"、
"标签":["字符串"]
}],
"自定义字段":[{
"字段":"string"、
"value": ["string"]
}],
"位置":"数字"、
"验证项已验证":"number"、
"verification_items_total": "number"、
"验证项目":[{
"status":"string"、
"component":"string"、
"标签":["字符串"]、
"活动":{
"名称":"string"(字符串
"验证方法":["字符串"]
},
"last_item_run":{
"状态":"string"、
"comment":"字符串"
}
}],
"linked_components":[{
"id":"number"、
"名称":"string"、
"值":[{
"id":"数字"、
"名称":"字符串"、
"值":"字符串"、
"公式":"字符串"
}],
"textvalis":[{
"id":"数字"、
"名称":"字符串"、
"文本":"字符串"
}],
"矩阵":[{
"id":"数字"、
"名称":"字符串"、
"值":"字符串"、
"公式":"字符串"
}],
"datevalis":[{
"id":"数字"、
"名称":"字符串"、
"日期":"字符串"
}],
"创建者":"字符串"、
"附件":[{
"名称":"string"、
"description":"字符串"、
"版本":"字符串"、
"is_reference": "布尔":"布尔"、
"标签":["字符串"]
}]
}]
}
],
"requirements_groups":[
{
"id":"编号"、
"名称":"字符串"、
"description":"字符串"、
"specification_id":"编号"、
"要求":[
{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"、
理由": "RichText", "文本": "RichText"RichText"、
"图像":["图像"]、
"类型":"字符串"、
"验证方法":[{
"名称":"string"、
"文本":"string"、
"component_vms":[{
"name":"string"、
"closeout_reference":"字符串"
}]
}],
"specification_id":"number"、
"group_id":"编号"、
"适用条件":["字符串"]、
"content_type"(内容类型):{
"id":"string"(字符串
"名称":"字符串"
},
"状态":"字符串"、
"遵从":"字符串"、
"compliance_comment":"字符串"、
"标签":["字符串"]、
"父母":[{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"
}],
"儿童":[{
"id":"string"、
"标识符":"字符串"、
"文本":"RichText"、
"标题":"字符串"
}],
"所有者":{
"user":{
"username":"string"、
"first_name":"string"、
"last_name":"字符串"、
"组":["字符串"]
},
"组":{
"名称":"字符串"、
"users":["字符串"]
}
},
"文件":[{
"名称":"string"、
"description":"字符串"、
"版本":"字符串"、
"is_reference": "布尔":"布尔"、
"标签":["字符串"]
}],
"自定义字段":[{
"字段":"string"、
"value": ["string"]
}],
"位置":"数字"、
"验证项已验证":"number"、
"verification_items_total": "number"、
"验证项目":[{
"status":"string"、
"component":"string"、
"标签":["字符串"]、
"活动":{
"名称":"string"(字符串
"验证方法":["字符串"]
},
"last_item_run":{
"状态":"string"、
"comment":"字符串"
}
}],
"linked_components":[{
"id":"number"、
"名称":"string"、
"值":[{
"id":"数字"、
"名称":"字符串"、
"值":"字符串"、
"公式":"字符串"
}],
"textvalis":[{
"id":"数字"、
"名称":"字符串"、
"文本":"字符串"
}],
"矩阵":[{
"id":"number"、
"名称":"字符串"、
"值":"字符串"、
"公式":"字符串"
}],
"datevalis":[{
"id":"数字"、
"名称":"字符串"、
"日期":"字符串"
}],
"创建者":"字符串"、
"附件":[{
"名称":"string"、
"description":"字符串"、
"版本":"字符串"、
"is_reference": "布尔":"布尔"、
"标签":["字符串"]
}]
}]
}
],
"content_type":{
"id":"号码"、
"名称":"string"
}
}
],
"时间戳":"datetime"、
"template_name":"字符串"、
"验证和确认方法":[{
"id":"number"、
"名称":"字符串"、
"description":"字符串"
}]
}
字段排序
您可以使用 Sort函数对需求进行排序。例如,你可以添加 |sort(attribute='identifier')其中,需求按标识符列的字母数字排序。
例如
{% for requirement in requirements|selectattr("specification_id", "equalto", specification.id)|selectattr("group_id", "none") |sort(attribute='identifier') -%}
自定义列
使用当前的文档导出器,可以轻松导出自定义列值。对于简单的基于文本的自定义列,可以使用以下通用结构:
{% for custom_field in requirement.custom_fields|selectattr(“field”, “equalto”, “Name of Custom Column”) %}{% for value in custom_field.value %}{{ value }}{% endfor %}{% endfor %}
请务必将 Name of Custom Column文本替换为列标题上显示的列的实际名称。
如果自定义列不是文本,而是多选选项,用户可以使用以下代码,并根据自己的使用情况进行更新。
{%- if requirement.custom_fields -%}
{%- set additional_info_values = [] -%}
{%- set category_values = [] -%}
{%- set additional_info_custom_fields = requirement.custom_fields | selectattr('field', 'equalto', 'Additional Information') -%}
{% for custom_field in additional_info_custom_fields -%}
{%- set additional_info_values = additional_info_values + custom_field.value -%}
{%- endfor -%}
{%- set category_custom_fields = requirement.custom_fields | selectattr('field', 'equalto', 'Category') -%}
{% for custom_field in category_custom_fields -%}
{%- set category_values = category_values + custom_field.value -%}
{% endfor -%}
{%- set additional_info_string = additional_info_values | join(';') -%}
{%- set category_string = category_info_values | join(';') -%}
{%- endif -%}
附录 - V&V 活动导出模板的数据对象结构
下面是 V&V 活动导出模板从中获取信息的对象的基本结构。
V&V Activity Export Templates – Data Object Structure
# 顶层
{
activities:[{}] # 所有活动列表
文件夹[{
name: string
activities:[{}] # 活动列表
}]
timestamp: datetime
template_name: string
}
# 活动
{
id: number
name: string
description: string
expected_results: string
tags:[字符串]
验证方法:[{
name: string
description: string
}]
所有者: 用户或组
custom_fields:[] # 自定义字段列表
批准: 布尔
items:[{}] # VVItems 列表
step_definitions:[{}] # StepDefinitions 列表
runs:[{}] # 活动运行列表
}
# VVItem
{
id: number
requirement_identifier: string
component:{ # 与 reqs 文档中的链接组件相同 export
id: number
name: string
valis:[{
id: 数字
name: string
value: string
公式:字符串
}]
textvalis:[{
id: 数字
name: string
text: string
}]
矩阵[{
id: 数字
name: string
value: string
公式:字符串
}]
datevalis:[{
id: 数字
name: string
date: string
}]
创建者:字符串
附件:[{
name: string
description: string
版本:字符串
is_reference: 布尔型
tags:[字符串]
}]
}
compliance: string
compliance_comment: string
last_item_run:{}# VVItemRun
last_item_run_status: 字符串
item_runs:[{}] # VVItemRuns 列表
}
# 步骤定义
{
id: int
activity_id: int
step_number: int
position: float
full_step_number: str
full_step_path: 字符串
parent_step_id: int
name: 字符串
description: string
expected_results: string
tags:[字符串]
item_ids: [] # VVItems ids 列表
}
# 活动运行
{
id: int
name: string
description: string
timestamp: string
start_date: string # 格式使用与 reqs 文档导出相同
finish_date: string
completion_state: int
completed_on: string
completed_by:用户
activity_id: int
default_run: bool
position: float
steps_synced: bool
expected_results: string
evidence: string # 文件/文档名称
custom_fields:[] # 自定义字段列表
tags:[字符串]
run_executor:{}# 用户或组
批准人{}# 用户或组
approved: 布尔型
approved_by:用户
approved_at: string
item_runs:[] # VVItemRuns 列表
step_runs:[{}] # VVStepRuns 列表
}
# VVItemRun
{
id: int
status: string
verified_by:用户
activity_run_id: int
status:"status-display-name
注释:字符串
serial_number: string
step_run_id: int # StepRun
verification_item:{}# VVItem
verification_item_requirement_identifier: string
verification_item_component_name: string
}
# StepRun
{
id: int
name: string
comment: string
status: string
description: string
activity_run_id: int
full_step_number: string
step_number: int
position: float
full_step_run_path: string
parent_step_run_id: int
expected_results: string
tags:[string] (字符串
item_run_ids: [] # VVItemRun id 列表
item_requirement_identifiers: str
}