From 83de78419632ccb74f75730cd80677f608933b54 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 30 Oct 2025 15:34:44 -0400 Subject: [PATCH] Add region & site group panels --- netbox/dcim/views.py | 3 +++ netbox/netbox/ui/components.py | 8 ++++++++ netbox/templates/dcim/region.html | 18 +----------------- netbox/templates/dcim/sitegroup.html | 18 +----------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 4e751d33f..e32a59a0b 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -17,6 +17,7 @@ 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.components import NestedGroupObjectPanel from netbox.views import generic from utilities.forms import ConfirmationForm from utilities.paginator import EnhancedPaginator, get_paginate_count @@ -227,6 +228,7 @@ class RegionView(GetRelatedModelsMixin, generic.ObjectView): regions = instance.get_descendants(include_self=True) return { + 'region_panel': NestedGroupObjectPanel(instance, _('Region')), 'related_models': self.get_related_models( request, regions, @@ -338,6 +340,7 @@ class SiteGroupView(GetRelatedModelsMixin, generic.ObjectView): groups = instance.get_descendants(include_self=True) return { + 'sitegroup_panel': NestedGroupObjectPanel(instance, _('Site Group')), 'related_models': self.get_related_models( request, groups, diff --git a/netbox/netbox/ui/components.py b/netbox/netbox/ui/components.py index c3aa1ae66..206086f17 100644 --- a/netbox/netbox/ui/components.py +++ b/netbox/netbox/ui/components.py @@ -2,7 +2,9 @@ from abc import ABC, ABCMeta, abstractmethod from functools import cached_property from django.template.loader import render_to_string +from django.utils.translation import gettext_lazy as _ +from netbox.ui import attrs from netbox.ui.attrs import Attr from utilities.string import title @@ -52,3 +54,9 @@ class ObjectPanel(Component, metaclass=ObjectDetailsPanelMeta): def __str__(self): return self.render() + + +class NestedGroupObjectPanel(ObjectPanel): + name = attrs.TextAttr('name', label=_('Name')) + description = attrs.TextAttr('description', label=_('Description')) + parent = attrs.NestedObjectAttr('parent', label=_('Parent'), linkify=True) diff --git a/netbox/templates/dcim/region.html b/netbox/templates/dcim/region.html index f11868b0a..28f4b6127 100644 --- a/netbox/templates/dcim/region.html +++ b/netbox/templates/dcim/region.html @@ -22,23 +22,7 @@ {% block content %}
-
-

{% trans "Region" %}

- - - - - - - - - - - - - -
{% trans "Name" %}{{ object.name }}
{% trans "Description" %}{{ object.description|placeholder }}
{% trans "Parent" %}{{ object.parent|linkify|placeholder }}
-
+ {{ region_panel }} {% include 'inc/panels/tags.html' %} {% include 'inc/panels/custom_fields.html' %} {% include 'inc/panels/comments.html' %} diff --git a/netbox/templates/dcim/sitegroup.html b/netbox/templates/dcim/sitegroup.html index dc9aca6f5..63e240dc6 100644 --- a/netbox/templates/dcim/sitegroup.html +++ b/netbox/templates/dcim/sitegroup.html @@ -22,23 +22,7 @@ {% block content %}
-
-

{% trans "Site Group" %}

- - - - - - - - - - - - - -
{% trans "Name" %}{{ object.name }}
{% trans "Description" %}{{ object.description|placeholder }}
{% trans "Parent" %}{{ object.parent|linkify|placeholder }}
-
+ {{ sitegroup_panel }} {% include 'inc/panels/tags.html' %} {% include 'inc/panels/custom_fields.html' %} {% include 'inc/panels/comments.html' %}