Пользовательские шаблоны экспорта документов
Мастер экспорта документов в Requirements & Systems Portal — ваш основной инструмент для быстрого создания редактируемых файлов Microsoft Word *.docx напрямую из ваших требований и операций V&V. Вы можете использовать предопределенные шаблоны или загружать собственные. Работа мастера основана на библиотеке Python-Docx-Template, которая, в свою очередь, использует механизм шаблонов Jinja. Этот мощный тандем позволяет создавать собственные шаблоны.
Библиотека Python-Docx-Template
Библиотека Python-Docx-Template — это мощный инструмент, расширяющий возможности библиотеки Python-Docx. Она включает механизм шаблонов Jinja, что позволяет динамически генерировать содержимое в ваших файлах Word. Это означает, что вы можете использовать переменные, циклы и условные конструкции для заполнения документа данными на лету. По сути, это как дать вашему документу Word заряд бодрости.
Управление шаблонами экспорта
Шаблоны, доступные для вашего экземпляра Requirements & Systems Portal, перечислены на странице Export templates » Settings » Export templates).
-
По умолчанию предоставляются шесть шаблонов — три для экспорта документов требований и три для экспорта документов операций V&V.
-
Дополнительные сведения о шаблонах экспорта требований см. на странице Document Export.
-
Дополнительные сведения о шаблонах экспорта операций V&V см. на странице Document Export.
-
-
Чтобы добавить новый пользовательский шаблон, нажмите кнопку
в правом верхнем углу страницы. В появившемся окне 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
{
"specifications": [
{
"id": "number",
"name": "string",
"description": "string",
"requirements": [
{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string",
"rationale": "RichText",
"images": ["image"],
"type": "string",
"verification_methods": [{
"name": "string",
"text": "string",
"component_vms": [{
"name": "string",
"closeout_reference": "string"
}]
}],
"specification_id": "number",
"group_id": "number",
"applicability_conditions": ["string"],
"content_type": {
"id": "string",
"name": "string"
},
"state": "string",
"compliance": "string",
"compliance_comment": "string",
"tags": ["string"],
"parents": [{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string"
}],
"children": [{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string"
}],
"owner": {
"user": {
"username": "string",
"first_name": "string",
"last_name": "string",
"groups": ["string"]
},
"group": {
"name": "string",
"users": ["string"]
}
},
"files": [{
"name": "string",
"description": "string",
"version": "string",
"is_reference": "boolean",
"tags": ["string"]
}],
"custom_fields": [{
"field": "string",
"value": ["string"]
}],
"position": "number",
"verification_items_verified": "number",
"verification_items_total": "number",
"verification_items": [{
"status": "string",
"component": "string",
"tags": ["string"],
"activity": {
"name": "string",
"verification_methods": ["string"]
},
"last_item_run": {
"status": "string",
"comment": "string"
}
}],
"linked_components": [{
"id": "number",
"name": "string",
"description": "string",
"valis": [{
"id": "number",
"name": "string",
"value": "string",
"formula": "string"
}],
"textvalis": [{
"id": "number",
"name": "string",
"text": "string"
}],
"matrices": [{
"id": "number",
"name": "string",
"value": "string",
"formula": "string"
}],
"datevalis": [{
"id": "number",
"name": "string",
"date": "string"
}],
"creator": "string",
"attachments": [{
"name": "string",
"description": "string",
"version": "string",
"is_reference": "boolean",
"tags": ["string"]
}]
}]
}
],
"content_type": {
"id": "number",
"name": "string"
}
}
],
"requirements": [
{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string",
"rationale": "RichText",
"images": ["image"],
"type": "string",
"verification_methods": [{
"name": "string",
"text": "string",
"component_vms": [{
"name": "string",
"closeout_reference": "string"
}]
}],
"specification_id": "number",
"group_id": "number",
"applicability_conditions": ["string"],
"content_type": {
"id": "string",
"name": "string"
},
"state": "string",
"compliance": "string",
"compliance_comment": "string",
"tags": ["string"],
"parents": [{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string"
}],
"children": [{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string"
}],
"owner": {
"user": {
"username": "string",
"first_name": "string",
"last_name": "string",
"groups": ["string"]
},
"group": {
"name": "string",
"users": ["string"]
}
},
"files": [{
"name": "string",
"description": "string",
"version": "string",
"is_reference": "boolean",
"tags": ["string"]
}],
"custom_fields": [{
"field": "string",
"value": ["string"]
}],
"position": "number",
"verification_items_verified": "number",
"verification_items_total": "number",
"verification_items": [{
"status": "string",
"component": "string",
"tags": ["string"],
"activity": {
"name": "string",
"verification_methods": ["string"]
},
"last_item_run": {
"status": "string",
"comment": "string"
}
}],
"linked_components": [{
"id": "number",
"name": "string",
"valis": [{
"id": "number",
"name": "string",
"value": "string",
"formula": "string"
}],
"textvalis": [{
"id": "number",
"name": "string",
"text": "string"
}],
"matrices": [{
"id": "number",
"name": "string",
"value": "string",
"formula": "string"
}],
"datevalis": [{
"id": "number",
"name": "string",
"date": "string"
}],
"creator": "string",
"attachments": [{
"name": "string",
"description": "string",
"version": "string",
"is_reference": "boolean",
"tags": ["string"]
}]
}]
}
],
"requirements_groups": [
{
"id": "number",
"name": "string",
"description": "string",
"specification_id": "number",
"requirements": [
{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string",
"rationale": "RichText",
"images": ["image"],
"type": "string",
"verification_methods": [{
"name": "string",
"text": "string",
"component_vms": [{
"name": "string",
"closeout_reference": "string"
}]
}],
"specification_id": "number",
"group_id": "number",
"applicability_conditions": ["string"],
"content_type": {
"id": "string",
"name": "string"
},
"state": "string",
"compliance": "string",
"compliance_comment": "string",
"tags": ["string"],
"parents": [{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string"
}],
"children": [{
"id": "string",
"identifier": "string",
"text": "RichText",
"title": "string"
}],
"owner": {
"user": {
"username": "string",
"first_name": "string",
"last_name": "string",
"groups": ["string"]
},
"group": {
"name": "string",
"users": ["string"]
}
},
"files": [{
"name": "string",
"description": "string",
"version": "string",
"is_reference": "boolean",
"tags": ["string"]
}],
"custom_fields": [{
"field": "string",
"value": ["string"]
}],
"position": "number",
"verification_items_verified": "number",
"verification_items_total": "number",
"verification_items": [{
"status": "string",
"component": "string",
"tags": ["string"],
"activity": {
"name": "string",
"verification_methods": ["string"]
},
"last_item_run": {
"status": "string",
"comment": "string"
}
}],
"linked_components": [{
"id": "number",
"name": "string",
"valis": [{
"id": "number",
"name": "string",
"value": "string",
"formula": "string"
}],
"textvalis": [{
"id": "number",
"name": "string",
"text": "string"
}],
"matrices": [{
"id": "number",
"name": "string",
"value": "string",
"formula": "string"
}],
"datevalis": [{
"id": "number",
"name": "string",
"date": "string"
}],
"creator": "string",
"attachments": [{
"name": "string",
"description": "string",
"version": "string",
"is_reference": "boolean",
"tags": ["string"]
}]
}]
}
],
"content_type": {
"id": "number",
"name": "string"
}
}
],
"timestamp": "datetime",
"template_name": "string",
"verification_and_validation_methods": [{
"id": "number",
"name": "string",
"description": "string"
}]
}
Сортировка полей
Вы можете сортировать требования с помощью функции Sort в документе шаблона Jinja. Например, можно добавить |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”) %}{{r custom_field.value }}{% 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
# TOP LEVEL
{
activities: [{}] # List of all Activities
folders: [{
name: string
activities: [{}] # List of Activities
}]
timestamp: datetime
template_name: string
}
# Activity
{
id: number
name: string
description: string
expected_results: string
tags: [string]
verification_methods: [{
name: string
description: string
}]
owner: User or Group
custom_fields: [] # List of CustomFields
approvals: boolean
items: [{}] # List of VVItems
step_definitions: [{}] # List of StepDefinitions
runs: [{}] # List of ActivityRuns
}
# VVItem
{
id: number
requirement_identifier: string
component: { # Same as linked components in the reqs doc export
id: number
name: string
valis: [{
id: number
name: string
value: string
formula: string
}]
textvalis: [{
id: number
name: string
text: string
}]
matrices: [{
id: number
name: string
value: string
formula: string
}]
datevalis: [{
id: number
name: string
date: string
}]
creator: string
attachments: [{
name: string
description: string
version: string
is_reference: boolean
tags: [string]
}]
}
compliance: string
compliance_comment: string
last_item_run: {} # VVItemRun
last_item_run_status: str
item_runs: [{}] # List of VVItemRuns
}
# StepDefinition
{
id: int
activity_id: int
step_number: int
position: float
full_step_number: str
full_step_path: str
parent_step_id: int
name: string
description: string
expected_results: string
tags: [string]
item_ids: [] # List of VVItems ids
}
# ActivityRun
{
id: int
name: string
description: string
timestamp: string
start_date: string # Format use same as in reqs doc export
finish_date: string
completion_state: int
completed_on: string
completed_by: User
activity_id: int
default_run: bool
position: float
steps_synced: bool
expected_results: string
evidence: string # File/Doc name
custom_fields: [] # List of CustomFields
tags: [string]
run_executor: {} # User or Group
approver: {} # User or Group
approved: boolean
approved_by: User
approved_at: string
item_runs: [] # List of VVItemRuns
step_runs: [{}] # List of VVStepRuns
}
# VVItemRun
{
id: int
status: string
verified_by: User
activity_run_id: int
status: "status-display-name"
comment: string
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: str
step_number: int
position: float
full_step_run_path: str
parent_step_run_id: int
expected_results: string
tags: [string]
item_run_ids: [] # List of VVItemRun ids
item_requirement_identifiers: str
}