소스 검색

Note that 'table' is a reserved name for ExportTemplates

Jeremy Stretch 5 년 전
부모
커밋
93353e94a2
3개의 변경된 파일14개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 1
      docs/additional-features/export-templates.md
  2. 9 1
      netbox/extras/models/models.py
  3. 1 1
      netbox/utilities/templates/buttons/export.html

+ 4 - 1
docs/additional-features/export-templates.md

@@ -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/).
 

+ 9 - 1
netbox/extras/models/models.py

@@ -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):
         """

+ 1 - 1
netbox/utilities/templates/buttons/export.html

@@ -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 %}