Skip to main content
Skip table of contents

Document Export Custom Templates

Introduction

Welcome to the Document Export wizard, a nifty feature that entered Valispace's v1.8x.xx release! This wizard is your go-to for whipping up editable Microsoft Word .docx files straight from your requirements. Initially, we offered three preset templates, but guess what? Now, you can upload your very own templates into the wizard. How cool is that?

The wizard is fueled by the Python-Docx-Template library, which, in turn, leverages the Jinja Templating Engine. This dynamic duo allows you to craft custom templates, similar to our existing script-based solution: the https://docs.valispace.com/vhd/specification-export-based-on-microsoft-word-templ .

Python-Docx-Template Library

The Python-Docx-Template library is a powerful tool that extends the functionality of the Python-Docx library. It incorporates the Jinja Templating Engine, enabling dynamic content generation within your Word files. This means you can use variables, loops, and conditionals to populate your document with data on the fly. Essentially, it's like giving your Word doc a shot of espresso.

Default Templates

In this documentation, we've covered three templates, each progressively more complex than the last. So, if you're looking to up your template game, tackling them in sequence is a smart move. Here's the lineup:

  1. Document View Document view Commented.docx
    This one is your straightforward, run-of-the-mill template meant to produce an identical output to the requirements Document View. It's excellent for beginners and covers simple loops and variables.

  2. Specification Export Specification Export Commented.docx
    Stepping it up a notch, this template introduces conditionals and filters. It's where things start to get spicy. It’s the Jinja version of our script-based Word template with merge fields.

  3. Requirements V&V Matrix V&V Matrix Documented.docx
    The grandmaster of our templates. This one's rich in nested loops and conditionals, and it even incorporates tables. If you can master this, you're basically a Jedi of document templating.

So there you go! You're all set to become the Document Export wizard's next wizard. May the templates ever be in your favour!

Feel free to add, remove, or modify sections to fit your documentation needs better.


Appendix - Data Object Structure

After going through the default template files in the order given above, you might feel adventurous enough to test the limits of what you can include in your reports.

Here’s the basic structure of the object from which your templates will pull information from:

PY
{
  "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"]
          }]
        }
      ]
    }
  ],
  "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"]
      }]
    }
  ],
  "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"]
          }]
        }
      ]
    }
  ],
  "timestamp": "datetime"
}

Sorting of the fields:

The Users can sort the requirements with the help of “Sort” function on the Jinja template document. For example, you can add “|sort(attribute='identifier')" where the requirements are sorted alphanumerically on the identifier column.

Example:

{% for requirement in requirements|selectattr("specification_id", "equalto", specification.id)|selectattr("group_id", "none") |sort(attribute='identifier') -%}

Custom Columns

With the current document exporter, the user can export the custom column values easily. For a simple text based custom column you can use the following generic structure:

CODE
{% for custom_field in requirement.custom_fields|selectattr(“field”, “equalto”, “Name of Custom Column”) %}{% for value in custom_field.value %}{{ value }}{% endfor %}{% endfor %}

Be sure to substitute “Name of Custom Column“ with the actual name of the column indicated on the column header.

If the custom column is not a text and is a multi-selection option, the user can use the following code and update it for their use case.

CODE
{%- 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 -%}      

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.