Przeglądaj źródła

Closes #4698: Improve display of template code for object in admin UI

Jeremy Stretch 5 lat temu
rodzic
commit
fae115b995
2 zmienionych plików z 50 dodań i 10 usunięć
  1. 4 0
      docs/release-notes/version-2.8.md
  2. 46 10
      netbox/extras/admin.py

+ 4 - 0
docs/release-notes/version-2.8.md

@@ -2,6 +2,10 @@
 
 
 ## v2.8.6 (FUTURE)
 ## v2.8.6 (FUTURE)
 
 
+### Enhancements
+
+* [#4698](https://github.com/netbox-community/netbox/issues/4698) - Improve display of template code for object in admin UI
+
 ### Bug Fixes
 ### Bug Fixes
 
 
 * [#4702](https://github.com/netbox-community/netbox/issues/4702) - Catch IntegrityError exception when adding a non-unique secret
 * [#4702](https://github.com/netbox-community/netbox/issues/4702) - Catch IntegrityError exception when adding a non-unique secret

+ 46 - 10
netbox/extras/admin.py

@@ -46,24 +46,19 @@ class WebhookAdmin(admin.ModelAdmin):
     form = WebhookForm
     form = WebhookForm
     fieldsets = (
     fieldsets = (
         (None, {
         (None, {
-            'fields': (
-                'name', 'obj_type', 'enabled',
-            )
+            'fields': ('name', 'obj_type', 'enabled')
         }),
         }),
         ('Events', {
         ('Events', {
-            'fields': (
-                'type_create', 'type_update', 'type_delete',
-            )
+            'fields': ('type_create', 'type_update', 'type_delete')
         }),
         }),
         ('HTTP Request', {
         ('HTTP Request', {
             'fields': (
             'fields': (
                 'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
                 'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
-            )
+            ),
+            'classes': ('monospace',)
         }),
         }),
         ('SSL', {
         ('SSL', {
-            'fields': (
-                'ssl_verification', 'ca_file_path',
-            )
+            'fields': ('ssl_verification', 'ca_file_path')
         })
         })
     )
     )
 
 
@@ -121,6 +116,8 @@ class CustomLinkForm(forms.ModelForm):
             'url': forms.Textarea,
             'url': forms.Textarea,
         }
         }
         help_texts = {
         help_texts = {
+            'weight': 'A numeric weight to influence the ordering of this link among its peers. Lower weights appear '
+                      'first in a list.',
             'text': 'Jinja2 template code for the link text. Reference the object as <code>{{ obj }}</code>. Links '
             'text': 'Jinja2 template code for the link text. Reference the object as <code>{{ obj }}</code>. Links '
                     'which render as empty text will not be displayed.',
                     'which render as empty text will not be displayed.',
             'url': 'Jinja2 template code for the link URL. Reference the object as <code>{{ obj }}</code>.',
             'url': 'Jinja2 template code for the link URL. Reference the object as <code>{{ obj }}</code>.',
@@ -136,6 +133,15 @@ class CustomLinkForm(forms.ModelForm):
 
 
 @admin.register(CustomLink)
 @admin.register(CustomLink)
 class CustomLinkAdmin(admin.ModelAdmin):
 class CustomLinkAdmin(admin.ModelAdmin):
+    fieldsets = (
+        ('Custom Link', {
+            'fields': ('content_type', 'name', 'group_name', 'weight', 'button_class', 'new_window')
+        }),
+        ('Templates', {
+            'fields': ('text', 'url'),
+            'classes': ('monospace',)
+        })
+    )
     list_display = [
     list_display = [
         'name', 'content_type', 'group_name', 'weight',
         'name', 'content_type', 'group_name', 'weight',
     ]
     ]
@@ -149,8 +155,29 @@ class CustomLinkAdmin(admin.ModelAdmin):
 # Graphs
 # Graphs
 #
 #
 
 
+class GraphForm(forms.ModelForm):
+
+    class Meta:
+        model = Graph
+        exclude = ()
+        widgets = {
+            'source': forms.Textarea,
+            'link': forms.Textarea,
+        }
+
+
 @admin.register(Graph)
 @admin.register(Graph)
 class GraphAdmin(admin.ModelAdmin):
 class GraphAdmin(admin.ModelAdmin):
+    fieldsets = (
+        ('Graph', {
+            'fields': ('type', 'name', 'weight')
+        }),
+        ('Templates', {
+            'fields': ('template_language', 'source', 'link'),
+            'classes': ('monospace',)
+        })
+    )
+    form = GraphForm
     list_display = [
     list_display = [
         'name', 'type', 'weight', 'template_language', 'source',
         'name', 'type', 'weight', 'template_language', 'source',
     ]
     ]
@@ -179,6 +206,15 @@ class ExportTemplateForm(forms.ModelForm):
 
 
 @admin.register(ExportTemplate)
 @admin.register(ExportTemplate)
 class ExportTemplateAdmin(admin.ModelAdmin):
 class ExportTemplateAdmin(admin.ModelAdmin):
+    fieldsets = (
+        ('Export Template', {
+            'fields': ('content_type', 'name', 'description', 'mime_type', 'file_extension')
+        }),
+        ('Content', {
+            'fields': ('template_language', 'template_code'),
+            'classes': ('monospace',)
+        })
+    )
     list_display = [
     list_display = [
         'name', 'content_type', 'description', 'mime_type', 'file_extension',
         'name', 'content_type', 'description', 'mime_type', 'file_extension',
     ]
     ]