Jeremy Stretch 3 месяцев назад
Родитель
Сommit
ed3dd019a7
3 измененных файлов с 47 добавлено и 42 удалено
  1. 2 2
      netbox/dcim/views.py
  2. 42 0
      netbox/extras/ui/panels.py
  3. 3 40
      netbox/netbox/ui/panels.py

+ 2 - 2
netbox/dcim/views.py

@@ -14,14 +14,14 @@ from django.views.generic import View
 
 from circuits.models import Circuit, CircuitTermination
 from dcim.ui import panels
+from extras.ui.panels import CustomFieldsPanel, ImageAttachmentsPanel, TagsPanel
 from extras.views import ObjectConfigContextView, ObjectRenderConfigView
 from ipam.models import ASN, IPAddress, Prefix, VLANGroup, VLAN
 from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
 from netbox.object_actions import *
 from netbox.ui import actions, layout
 from netbox.ui.panels import (
-    CommentsPanel, CustomFieldsPanel, ImageAttachmentsPanel, NestedGroupObjectPanel, ObjectsTablePanel,
-    PluginContentPanel, RelatedObjectsPanel, TagsPanel,
+    CommentsPanel, NestedGroupObjectPanel, ObjectsTablePanel, PluginContentPanel, RelatedObjectsPanel,
 )
 from netbox.views import generic
 from utilities.forms import ConfirmationForm

+ 42 - 0
netbox/extras/ui/panels.py

@@ -0,0 +1,42 @@
+from django.contrib.contenttypes.models import ContentType
+from django.utils.translation import gettext_lazy as _
+
+from netbox.ui import actions, panels
+
+__all__ = (
+    'CustomFieldsPanel',
+    'ImageAttachmentsPanel',
+    'TagsPanel',
+)
+
+
+class CustomFieldsPanel(panels.Panel):
+    template_name = 'ui/panels/custom_fields.html'
+    title = _('Custom Fields')
+
+    def get_context(self, obj):
+        return {
+            'custom_fields': obj.get_custom_fields_by_group(),
+        }
+
+
+class ImageAttachmentsPanel(panels.ObjectsTablePanel):
+    actions = [
+        actions.AddObject(
+            'extras.imageattachment',
+            url_params={
+                'object_type': lambda obj: ContentType.objects.get_for_model(obj).pk,
+                'object_id': lambda obj: obj.pk,
+                'return_url': lambda obj: obj.get_absolute_url(),
+            },
+            label=_('Attach an image'),
+        ),
+    ]
+
+    def __init__(self, **kwargs):
+        super().__init__('extras.imageattachment', **kwargs)
+
+
+class TagsPanel(panels.Panel):
+    template_name = 'ui/panels/tags.html'
+    title = _('Tags')

+ 3 - 40
netbox/netbox/ui/panels.py

@@ -1,12 +1,10 @@
 from abc import ABC, ABCMeta
 
 from django.apps import apps
-from django.contrib.contenttypes.models import ContentType
 from django.template.loader import render_to_string
 from django.utils.translation import gettext_lazy as _
 
-from netbox.ui import actions, attrs
-from netbox.ui.attrs import Attr
+from netbox.ui import attrs
 from utilities.querydict import dict_to_querydict
 from utilities.string import title
 from utilities.templatetags.plugins import _get_registered_content
@@ -14,8 +12,6 @@ from utilities.views import get_viewname
 
 __all__ = (
     'CommentsPanel',
-    'CustomFieldsPanel',
-    'ImageAttachmentsPanel',
     'NestedGroupObjectPanel',
     'ObjectPanel',
     'ObjectsTablePanel',
@@ -23,7 +19,6 @@ __all__ = (
     'RelatedObjectsPanel',
     'Panel',
     'PluginContentPanel',
-    'TagsPanel',
 )
 
 
@@ -65,13 +60,13 @@ class ObjectPanelMeta(ABCMeta):
 
         # Add local declarations in the order they appear in the class body
         for key, attr in namespace.items():
-            if isinstance(attr, Attr):
+            if isinstance(attr, attrs.Attr):
                 declared[key] = attr
 
         namespace['_attrs'] = declared
 
         # Remove Attrs from the class namespace to keep things tidy
-        local_items = [key for key, attr in namespace.items() if isinstance(attr, Attr)]
+        local_items = [key for key, attr in namespace.items() if isinstance(attr, attrs.Attr)]
         for key in local_items:
             namespace.pop(key)
 
@@ -103,21 +98,6 @@ class NestedGroupObjectPanel(OrganizationalObjectPanel, metaclass=ObjectPanelMet
     parent = attrs.NestedObjectAttr('parent', label=_('Parent'), linkify=True)
 
 
-class CustomFieldsPanel(Panel):
-    template_name = 'ui/panels/custom_fields.html'
-    title = _('Custom Fields')
-
-    def get_context(self, obj):
-        return {
-            'custom_fields': obj.get_custom_fields_by_group(),
-        }
-
-
-class TagsPanel(Panel):
-    template_name = 'ui/panels/tags.html'
-    title = _('Tags')
-
-
 class CommentsPanel(Panel):
     template_name = 'ui/panels/comments.html'
     title = _('Comments')
@@ -162,23 +142,6 @@ class ObjectsTablePanel(Panel):
         }
 
 
-class ImageAttachmentsPanel(ObjectsTablePanel):
-    actions = [
-        actions.AddObject(
-            'extras.imageattachment',
-            url_params={
-                'object_type': lambda obj: ContentType.objects.get_for_model(obj).pk,
-                'object_id': lambda obj: obj.pk,
-                'return_url': lambda obj: obj.get_absolute_url(),
-            },
-            label=_('Attach an image'),
-        ),
-    ]
-
-    def __init__(self, **kwargs):
-        super().__init__('extras.imageattachment', **kwargs)
-
-
 class PluginContentPanel(Panel):
 
     def __init__(self, method, **kwargs):