Note that 'table' is a reserved name for ExportTemplates

This commit is contained in:
Jeremy Stretch 2021-03-29 11:25:22 -04:00
parent 30e4504ee5
commit 93353e94a2
3 changed files with 14 additions and 3 deletions

View File

@ -2,7 +2,10 @@
NetBox allows users to define custom templates that can be used when exporting objects. To create an export template, navigate to Extras > Export Templates under the admin interface.
Each export template is associated with a certain type of object. For instance, if you create an export template for VLANs, your custom template will appear under the "Export" button on the VLANs list.
Each export template is associated with a certain type of object. For instance, if you create an export template for VLANs, your custom template will appear under the "Export" button on the VLANs list. Each export template must have a name, and may optionally designate a specific export [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) and/or file extension.
!!! note
The name `table` is reserved for internal use.
Export templates must be written in [Jinja2](https://jinja.palletsprojects.com/).

View File

@ -261,7 +261,15 @@ class ExportTemplate(BigIDModel):
]
def __str__(self):
return '{}: {}'.format(self.content_type, self.name)
return f"{self.content_type}: {self.name}"
def clean(self):
super().clean()
if self.name.lower() == 'table':
raise ValidationError({
'name': f'"{self.name}" is a reserved name. Please choose a different name.'
})
def render(self, queryset):
"""

View File

@ -5,7 +5,7 @@
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export=table">Current view</a></li>
<li><a href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export">Default format</a></li>
<li><a href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export">Legacy CSV</a></li>
{% if export_templates %}
<li class="divider"></li>
{% for et in export_templates %}