Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
w1tht0uchp4d opened this issue Oct 1, 2024 · 1 comment
Assignees
Labels
complexity: low Requires minimal effort to implement netbox status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@w1tht0uchp4d
Copy link

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 w1tht0uchp4d added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels Oct 1, 2024
@pl0xym0r
Copy link
Contributor

pl0xym0r commented Oct 7, 2024

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.

@jeremystretch jeremystretch added the netbox label Nov 1, 2024 — with Linear
@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release status: backlog Awaiting selection for work complexity: low Requires minimal effort to implement and removed status: needs triage This issue is awaiting triage by a maintainer labels Feb 6, 2025
@jeremystretch jeremystretch removed the needs milestone Awaiting prioritization for inclusion with a future NetBox release label Feb 20, 2025
@jeremystretch jeremystretch added this to the v4.3 milestone Feb 20, 2025
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: backlog Awaiting selection for work labels Apr 1, 2025
jeremystretch added a commit that referenced this issue Apr 8, 2025
…ia jinja environment settings (#19078)

* Create RenderMixin, and unify template_code rendering and exporting

* Join migrations

* Add DEFAULT_MIME_TE constant

* Move RenderMixin to extras.models.mixins, Rename RenderMixin to RenderTemplateMixin

* Add render_jinja2 to __all__

* Rename ConfigTemplateFilterForm rendering FieldSet

* ConfigTemplate lint

* Simplify ExportTemplate get_context

* Fix table order, and add fields for translations

* Update Serializers

* Update forms, tables, graphQL, API

* Add extra tests for ConfigTemplate and ExportTemplate

* Documentation update

* Fix typo

* Misc cleanup

* Clean up template layouts

---------

Co-authored-by: Jeremy Stretch <[email protected]>
jnovinger added a commit that referenced this issue May 23, 2025
…plates

The ability to render nested templates was accidentally removed with the
implementation of #17653, which normalized the behavior of various Jinja2
template rendering actions.

This fix restores that behavior while retaining the normalized behavior.
This fix also includes regression tests to ensure this behavior is not
removed accidentally again in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: low Requires minimal effort to implement netbox status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

4 participants