netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Add function to trim whitespaces in export templates via jinja environment settings

Open w1tht0uchp4d opened this issue 1 year ago • 1 comments

NetBox version

3.7.5

Feature type

Change to existing functionality

Proposed functionality

The goal is to achieve feature parity between the [Provisioning --> Config Templates edit] and [Customization --> Export Templates dialog]. In config templates it is possible to use jinja environment parameters, in export templates it is not. It's also the same behavior in Netbox v4.1.2 (checked via demo application).

Use case

I'm currently implementing a custom export template, which exports prefixes, their assigned VLANs and some custom fields. I'm aware that part of this, is also achievable via the csv export function, but I want to add some semantic sugar via the power of Jinja, like adding first host address, last host address, ... The messy white space handling with jinja, unfortunately destroys the formatting of the csv.

Database changes

None required?

External dependencies

None?

w1tht0uchp4d avatar Oct 01 '24 17:10 w1tht0uchp4d

Both ConfigTemplate and ExportTemplate inherits from ExportTemplatesMixin

In ConfigTemplate there are params/methods like: environment_params def render() def _get_environment()

Idk if it's too much for export templates but would it be great to move such params/functions to ExportTemplatesMixin ? Or modify utilities.jinja2.py ? At least, use the same enviroment creation for both cases.

pl0xym0r avatar Oct 07 '24 13:10 pl0xym0r