[PR #19078] [MERGED] Closes #17653 Add function to trim whitespaces in export templates via jinja environment settings #15524

Closed
opened 2025-12-30 00:22:28 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/19078
Author: @renatoalmeidaoliveira
Created: 4/4/2025
Status: Merged
Merged: 4/8/2025
Merged by: @jeremystretch

Base: featureHead: 17653-add-extra-fields-and-render-params-to-ConfigTemplate


📝 Commits (10+)

  • fa8343b Create RenderMixin, and unify template_code rendering and exporting
  • 040ee1d Join migrations
  • fea7926 Add DEFAULT_MIME_TE constant
  • 517c801 Move RenderMixin to extras.models.mixins, Rename RenderMixin to RenderTemplateMixin
  • 48a32ac Add render_jinja2 to all
  • 749fdbf Rename ConfigTemplateFilterForm rendering FieldSet
  • 69dad27 ConfigTemplate lint
  • c7b17a2 Simplify ExportTemplate get_context
  • c53ca79 Fix table order, and add fields for translations
  • 178cd75 Update Serializers

📊 Changes

27 files changed (+437 additions, -188 deletions)

View changed files

📝 docs/models/extras/configtemplate.md (+24 -4)
📝 docs/models/extras/exporttemplate.md (+6 -2)
📝 netbox/dcim/views.py (+1 -5)
📝 netbox/extras/api/serializers_/configtemplates.py (+2 -1)
📝 netbox/extras/api/serializers_/exporttemplates.py (+3 -3)
📝 netbox/extras/constants.py (+3 -0)
📝 netbox/extras/filtersets.py (+4 -1)
📝 netbox/extras/forms/bulk_edit.py (+20 -1)
📝 netbox/extras/forms/bulk_import.py (+4 -3)
📝 netbox/extras/forms/filtersets.py (+22 -2)
📝 netbox/extras/forms/model_forms.py (+7 -3)
📝 netbox/extras/graphql/filters.py (+8 -0)
netbox/extras/migrations/0126_configtemplate_as_attachment_and_more.py (+38 -0)
📝 netbox/extras/models/configs.py (+7 -56)
📝 netbox/extras/models/mixins.py (+92 -0)
📝 netbox/extras/models/models.py (+11 -60)
📝 netbox/extras/tables/tables.py (+25 -2)
📝 netbox/extras/tests/test_api.py (+5 -1)
📝 netbox/extras/tests/test_filtersets.py (+78 -20)
📝 netbox/extras/tests/test_views.py (+26 -4)

...and 7 more files

📄 Description

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

  • Creates RenderMixin model with fields: template_code, environment_params, mime_type, file_name, file_extension, as_attachment
  • Add RenderMixin to ExportTemplate and ConfigTemplate, removing the repeated fields
  • Unify the export logic inside RenderMixin using ExportTemplate as reference for exports, i.e. always using template_code instead of using data_file when exists, because template_code should be equals to data_file after sync and it gives the end user more control of what template is in use.

Extra Comments:

  • Allowing the user to setup file_name and file_extension to ConfigTemplate may give the user more flexibility in ZTP use cases using NetBox as source of python ZTP configuration files,

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/19078 **Author:** [@renatoalmeidaoliveira](https://github.com/renatoalmeidaoliveira) **Created:** 4/4/2025 **Status:** ✅ Merged **Merged:** 4/8/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `17653-add-extra-fields-and-render-params-to-ConfigTemplate` --- ### 📝 Commits (10+) - [`fa8343b`](https://github.com/netbox-community/netbox/commit/fa8343b7cb1d6d83c55dbedc495754ed3bdbffd6) Create RenderMixin, and unify template_code rendering and exporting - [`040ee1d`](https://github.com/netbox-community/netbox/commit/040ee1d8f739561a1814e7ad092a3649f0085312) Join migrations - [`fea7926`](https://github.com/netbox-community/netbox/commit/fea7926197573ddc5c0a57de955c5999b51f8859) Add DEFAULT_MIME_TE constant - [`517c801`](https://github.com/netbox-community/netbox/commit/517c8016c331d8cc3b025c4bab912d347f79d254) Move RenderMixin to extras.models.mixins, Rename RenderMixin to RenderTemplateMixin - [`48a32ac`](https://github.com/netbox-community/netbox/commit/48a32aca3dab85db74692790037ed4c0c91c0407) Add render_jinja2 to __all__ - [`749fdbf`](https://github.com/netbox-community/netbox/commit/749fdbf92ec52b91f740938ebccf46e05bb0008a) Rename ConfigTemplateFilterForm rendering FieldSet - [`69dad27`](https://github.com/netbox-community/netbox/commit/69dad278666b5b802309a7daa8a6f6438a933644) ConfigTemplate lint - [`c7b17a2`](https://github.com/netbox-community/netbox/commit/c7b17a26d97a224bb7f69f1dbef4633b6ef91144) Simplify ExportTemplate get_context - [`c53ca79`](https://github.com/netbox-community/netbox/commit/c53ca79bd7cefe307a430f12f12e972b00c50abe) Fix table order, and add fields for translations - [`178cd75`](https://github.com/netbox-community/netbox/commit/178cd75b8c9467394ab886c978309f97674a5bf4) Update Serializers ### 📊 Changes **27 files changed** (+437 additions, -188 deletions) <details> <summary>View changed files</summary> 📝 `docs/models/extras/configtemplate.md` (+24 -4) 📝 `docs/models/extras/exporttemplate.md` (+6 -2) 📝 `netbox/dcim/views.py` (+1 -5) 📝 `netbox/extras/api/serializers_/configtemplates.py` (+2 -1) 📝 `netbox/extras/api/serializers_/exporttemplates.py` (+3 -3) 📝 `netbox/extras/constants.py` (+3 -0) 📝 `netbox/extras/filtersets.py` (+4 -1) 📝 `netbox/extras/forms/bulk_edit.py` (+20 -1) 📝 `netbox/extras/forms/bulk_import.py` (+4 -3) 📝 `netbox/extras/forms/filtersets.py` (+22 -2) 📝 `netbox/extras/forms/model_forms.py` (+7 -3) 📝 `netbox/extras/graphql/filters.py` (+8 -0) ➕ `netbox/extras/migrations/0126_configtemplate_as_attachment_and_more.py` (+38 -0) 📝 `netbox/extras/models/configs.py` (+7 -56) 📝 `netbox/extras/models/mixins.py` (+92 -0) 📝 `netbox/extras/models/models.py` (+11 -60) 📝 `netbox/extras/tables/tables.py` (+25 -2) 📝 `netbox/extras/tests/test_api.py` (+5 -1) 📝 `netbox/extras/tests/test_filtersets.py` (+78 -20) 📝 `netbox/extras/tests/test_views.py` (+26 -4) _...and 7 more files_ </details> ### 📄 Description ### Fixes: #17653 Add function to trim whitespaces in export templates via jinja environment settings - Creates `RenderMixin` model with fields: `template_code`, `environment_params`, `mime_type`, `file_name`, `file_extension`, `as_attachment` - Add `RenderMixin` to `ExportTemplate` and `ConfigTemplate`, removing the repeated fields - Unify the export logic inside `RenderMixin` using `ExportTemplate` as reference for exports, i.e. always using `template_code` instead of using `data_file` when exists, because `template_code` should be equals to `data_file` after `sync` and it gives the end user more control of what template is in use. Extra Comments: - Allowing the user to setup `file_name` and `file_extension` to `ConfigTemplate` may give the user more flexibility in ZTP use cases using NetBox as source of python ZTP configuration files, --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:22:28 +01:00
adam closed this issue 2025-12-30 00:22:28 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15524