Procházet zdrojové kódy

Move some panels to extras

Jeremy Stretch před 3 měsíci
rodič
revize
ed3dd019a7
3 změnil soubory, kde provedl 47 přidání a 42 odebrání
  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 circuits.models import Circuit, CircuitTermination
 from dcim.ui import panels
 from dcim.ui import panels
+from extras.ui.panels import CustomFieldsPanel, ImageAttachmentsPanel, TagsPanel
 from extras.views import ObjectConfigContextView, ObjectRenderConfigView
 from extras.views import ObjectConfigContextView, ObjectRenderConfigView
 from ipam.models import ASN, IPAddress, Prefix, VLANGroup, VLAN
 from ipam.models import ASN, IPAddress, Prefix, VLANGroup, VLAN
 from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
 from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
 from netbox.object_actions import *
 from netbox.object_actions import *
 from netbox.ui import actions, layout
 from netbox.ui import actions, layout
 from netbox.ui.panels import (
 from netbox.ui.panels import (
-    CommentsPanel, CustomFieldsPanel, ImageAttachmentsPanel, NestedGroupObjectPanel, ObjectsTablePanel,
-    PluginContentPanel, RelatedObjectsPanel, TagsPanel,
+    CommentsPanel, NestedGroupObjectPanel, ObjectsTablePanel, PluginContentPanel, RelatedObjectsPanel,
 )
 )
 from netbox.views import generic
 from netbox.views import generic
 from utilities.forms import ConfirmationForm
 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 abc import ABC, ABCMeta
 
 
 from django.apps import apps
 from django.apps import apps
-from django.contrib.contenttypes.models import ContentType
 from django.template.loader import render_to_string
 from django.template.loader import render_to_string
 from django.utils.translation import gettext_lazy as _
 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.querydict import dict_to_querydict
 from utilities.string import title
 from utilities.string import title
 from utilities.templatetags.plugins import _get_registered_content
 from utilities.templatetags.plugins import _get_registered_content
@@ -14,8 +12,6 @@ from utilities.views import get_viewname
 
 
 __all__ = (
 __all__ = (
     'CommentsPanel',
     'CommentsPanel',
-    'CustomFieldsPanel',
-    'ImageAttachmentsPanel',
     'NestedGroupObjectPanel',
     'NestedGroupObjectPanel',
     'ObjectPanel',
     'ObjectPanel',
     'ObjectsTablePanel',
     'ObjectsTablePanel',
@@ -23,7 +19,6 @@ __all__ = (
     'RelatedObjectsPanel',
     'RelatedObjectsPanel',
     'Panel',
     'Panel',
     'PluginContentPanel',
     'PluginContentPanel',
-    'TagsPanel',
 )
 )
 
 
 
 
@@ -65,13 +60,13 @@ class ObjectPanelMeta(ABCMeta):
 
 
         # Add local declarations in the order they appear in the class body
         # Add local declarations in the order they appear in the class body
         for key, attr in namespace.items():
         for key, attr in namespace.items():
-            if isinstance(attr, Attr):
+            if isinstance(attr, attrs.Attr):
                 declared[key] = attr
                 declared[key] = attr
 
 
         namespace['_attrs'] = declared
         namespace['_attrs'] = declared
 
 
         # Remove Attrs from the class namespace to keep things tidy
         # 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:
         for key in local_items:
             namespace.pop(key)
             namespace.pop(key)
 
 
@@ -103,21 +98,6 @@ class NestedGroupObjectPanel(OrganizationalObjectPanel, metaclass=ObjectPanelMet
     parent = attrs.NestedObjectAttr('parent', label=_('Parent'), linkify=True)
     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):
 class CommentsPanel(Panel):
     template_name = 'ui/panels/comments.html'
     template_name = 'ui/panels/comments.html'
     title = _('Comments')
     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):
 class PluginContentPanel(Panel):
 
 
     def __init__(self, method, **kwargs):
     def __init__(self, method, **kwargs):