mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-14 04:19:36 -06:00
Move some panels to extras
This commit is contained in:
parent
17cffd7860
commit
ed3dd019a7
@ -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,
|
CommentsPanel, NestedGroupObjectPanel, ObjectsTablePanel, PluginContentPanel, RelatedObjectsPanel,
|
||||||
PluginContentPanel, RelatedObjectsPanel, TagsPanel,
|
|
||||||
)
|
)
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from utilities.forms import ConfirmationForm
|
from utilities.forms import ConfirmationForm
|
||||||
|
|||||||
42
netbox/extras/ui/panels.py
Normal file
42
netbox/extras/ui/panels.py
Normal file
@ -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')
|
||||||
@ -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 import attrs
|
||||||
from netbox.ui.attrs import Attr
|
|
||||||
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):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user