Requirements & Systems Portal 的文档导出向导是您从需求和 V&V 活动中直接生成可编辑 Microsoft Word *.docx文件。您可以使用预定义模板或上传自己的模板。该向导由 Python-Docx-Template 库驱动,而 Python-Docx-Template 库又利用了 Jinja 模板引擎。通过这对动态组合,您可以制作自定义模板。
*.docx
Python-Docx-Template 库是扩展 Python-Docx 库功能的强大工具。它集成了 Jinja 模板引擎,可在 Word 文件中生成动态内容。这意味着您可以使用变量、循环和条件,在文档中即时填充数据。从本质上讲,这就像是给 Word 文档加了一杯浓咖啡。
请注意,对于富文本字段,必须在导出模板中使用 r前缀必须在导出模板中使用。例如,要求文本字段必须在模板中包含 r requirement.text.
r
r requirement.text
需求与系统门户实例可用的模板列在 Export templates页面 ( » Settings » Export templates).
默认情况下,提供六个模板--三个用于需求文档导出,三个用于 V&V 活动文档导出。
有关需求导出模板的更多信息,请参阅 "文档导出"页面。
有关 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选项,然后单击 按钮完成该过程。
需求与系统门户实例中有三个默认的需求导出模板,每一个都比上一个复杂。因此,如果你想提高你的模板水平,依次处理它们是明智之举。下面是它们的阵容
spec_doc.docx- 这一个是简单、普通的模板,旨在产生与需求文档视图相同的输出。它非常适合初学者,涵盖了简单的循环和变量。
spec_table.docx- 在此基础上,该模板引入了条件和过滤器。这就是事情开始变得有趣的地方。这是我们基于脚本的 Word 模板的 Jinja 版本,带有合并字段。
req_verification.docx- 我们的模板大师。这个模板有丰富的嵌套循环和条件,甚至还加入了表格。如果你能熟练掌握它,那你基本上就是文档模板的绝地武士了。
请随意添加、删除或修改部分,以更好地满足你的文档需求。按照上述顺序浏览完默认模板文件后,你可能会觉得自己很有冒险精神,想测试一下自己能在报告中包含哪些内容。
以下是需求导出模板将从中获取信息的对象的基本结构。
{ "规格":[ { "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')其中,需求按标识符列的字母数字排序。
|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文本替换为列标题上显示的列的实际名称。
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 活动导出模板从中获取信息的对象的基本结构。
# 顶层 { 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 }
您可使用的功能取决于您所选择的 Altium 解决方案 —— Altium Develop、Altium Agile(Agile Teams 或 Agile Enterprise 版本),或仍在有效订阅期内的 Altium Designer。
如果您在软件中未找到文中提及的功能,请联系 Altium 销售团队了解更多信息。