Skip to content

Commit a024012

Browse files
committed
Misc cleanup
1 parent 6fc04bd commit a024012

File tree

7 files changed

+210
-96
lines changed

7 files changed

+210
-96
lines changed

netbox/dcim/ui/panels.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class SitePanel(panels.ObjectAttributesPanel):
77
region = attrs.NestedObjectAttr('region', linkify=True)
88
group = attrs.NestedObjectAttr('group', linkify=True)
99
status = attrs.ChoiceAttr('status')
10-
tenant = attrs.ObjectAttr('tenant', linkify=True, grouped_by='group')
10+
tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
1111
facility = attrs.TextAttr('facility')
1212
description = attrs.TextAttr('description')
1313
timezone = attrs.TimezoneAttr('time_zone')
@@ -17,9 +17,9 @@ class SitePanel(panels.ObjectAttributesPanel):
1717

1818

1919
class LocationPanel(panels.NestedGroupObjectPanel):
20-
site = attrs.ObjectAttr('site', linkify=True, grouped_by='group')
20+
site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group')
2121
status = attrs.ChoiceAttr('status')
22-
tenant = attrs.ObjectAttr('tenant', linkify=True, grouped_by='group')
22+
tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
2323
facility = attrs.TextAttr('facility')
2424

2525

@@ -40,13 +40,13 @@ class RackNumberingPanel(panels.ObjectAttributesPanel):
4040

4141
class RackPanel(panels.ObjectAttributesPanel):
4242
region = attrs.NestedObjectAttr('site.region', linkify=True)
43-
site = attrs.ObjectAttr('site', linkify=True, grouped_by='group')
43+
site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group')
4444
location = attrs.NestedObjectAttr('location', linkify=True)
4545
facility = attrs.TextAttr('facility')
46-
tenant = attrs.ObjectAttr('tenant', linkify=True, grouped_by='group')
46+
tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
4747
status = attrs.ChoiceAttr('status')
48-
rack_type = attrs.ObjectAttr('rack_type', linkify=True, grouped_by='manufacturer')
49-
role = attrs.ObjectAttr('role', linkify=True)
48+
rack_type = attrs.RelatedObjectAttr('rack_type', linkify=True, grouped_by='manufacturer')
49+
role = attrs.RelatedObjectAttr('role', linkify=True)
5050
description = attrs.TextAttr('description')
5151
serial = attrs.TextAttr('serial', label=_('Serial number'), style='font-monospace', copy_button=True)
5252
asset_tag = attrs.TextAttr('asset_tag', style='font-monospace', copy_button=True)
@@ -66,26 +66,26 @@ class RackRolePanel(panels.OrganizationalObjectPanel):
6666

6767

6868
class RackTypePanel(panels.ObjectAttributesPanel):
69-
manufacturer = attrs.ObjectAttr('manufacturer', linkify=True)
69+
manufacturer = attrs.RelatedObjectAttr('manufacturer', linkify=True)
7070
model = attrs.TextAttr('model')
7171
description = attrs.TextAttr('description')
7272

7373

7474
class DevicePanel(panels.ObjectAttributesPanel):
7575
region = attrs.NestedObjectAttr('site.region', linkify=True)
76-
site = attrs.ObjectAttr('site', linkify=True, grouped_by='group')
76+
site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group')
7777
location = attrs.NestedObjectAttr('location', linkify=True)
7878
rack = attrs.TemplatedAttr('rack', template_name='dcim/device/attrs/rack.html')
79-
virtual_chassis = attrs.ObjectAttr('virtual_chassis', linkify=True)
79+
virtual_chassis = attrs.RelatedObjectAttr('virtual_chassis', linkify=True)
8080
parent_device = attrs.TemplatedAttr('parent_bay', template_name='dcim/device/attrs/parent_device.html')
8181
gps_coordinates = attrs.GPSCoordinatesAttr()
82-
tenant = attrs.ObjectAttr('tenant', linkify=True, grouped_by='group')
83-
device_type = attrs.ObjectAttr('device_type', linkify=True, grouped_by='manufacturer')
82+
tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
83+
device_type = attrs.RelatedObjectAttr('device_type', linkify=True, grouped_by='manufacturer')
8484
description = attrs.TextAttr('description')
8585
airflow = attrs.ChoiceAttr('airflow')
8686
serial = attrs.TextAttr('serial', label=_('Serial number'), style='font-monospace', copy_button=True)
8787
asset_tag = attrs.TextAttr('asset_tag', style='font-monospace', copy_button=True)
88-
config_template = attrs.ObjectAttr('config_template', linkify=True)
88+
config_template = attrs.RelatedObjectAttr('config_template', linkify=True)
8989

9090

9191
class DeviceManagementPanel(panels.ObjectAttributesPanel):
@@ -109,7 +109,7 @@ class DeviceManagementPanel(panels.ObjectAttributesPanel):
109109
label=_('Out-of-band IP'),
110110
template_name='dcim/device/attrs/ipaddress.html',
111111
)
112-
cluster = attrs.ObjectAttr('cluster', linkify=True)
112+
cluster = attrs.RelatedObjectAttr('cluster', linkify=True)
113113

114114

115115
class DeviceDimensionsPanel(panels.ObjectAttributesPanel):
@@ -120,10 +120,10 @@ class DeviceDimensionsPanel(panels.ObjectAttributesPanel):
120120

121121

122122
class DeviceTypePanel(panels.ObjectAttributesPanel):
123-
manufacturer = attrs.ObjectAttr('manufacturer', linkify=True)
123+
manufacturer = attrs.RelatedObjectAttr('manufacturer', linkify=True)
124124
model = attrs.TextAttr('model')
125125
part_number = attrs.TextAttr('part_number')
126-
default_platform = attrs.ObjectAttr('default_platform', linkify=True)
126+
default_platform = attrs.RelatedObjectAttr('default_platform', linkify=True)
127127
description = attrs.TextAttr('description')
128128
height = attrs.TextAttr('u_height', format_string='{}U', label=_('Height'))
129129
exclude_from_utilization = attrs.BooleanAttr('exclude_from_utilization')

netbox/extras/ui/panels.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.utils.translation import gettext_lazy as _
44

55
from netbox.ui import actions, panels
6+
from utilities.data import resolve_attr_path
67

78
__all__ = (
89
'CustomFieldsPanel',
@@ -13,13 +14,13 @@
1314

1415
class CustomFieldsPanel(panels.ObjectPanel):
1516
"""
16-
Render a panel showing the value of all custom fields defined on the object.
17+
A panel showing the value of all custom fields defined on an object.
1718
"""
1819
template_name = 'extras/panels/custom_fields.html'
1920
title = _('Custom Fields')
2021

2122
def get_context(self, context):
22-
obj = context['object']
23+
obj = resolve_attr_path(context, self.accessor)
2324
return {
2425
**super().get_context(context),
2526
'custom_fields': obj.get_custom_fields_by_group(),
@@ -35,7 +36,7 @@ def render(self, context):
3536

3637
class ImageAttachmentsPanel(panels.ObjectsTablePanel):
3738
"""
38-
Render a table listing all images attached to the object.
39+
A panel showing all images attached to the object.
3940
"""
4041
actions = [
4142
actions.AddObject(
@@ -55,13 +56,13 @@ def __init__(self, **kwargs):
5556

5657
class TagsPanel(panels.ObjectPanel):
5758
"""
58-
Render a panel showing the tags assigned to the object.
59+
A panel showing the tags assigned to the object.
5960
"""
6061
template_name = 'extras/panels/tags.html'
6162
title = _('Tags')
6263

6364
def get_context(self, context):
6465
return {
6566
**super().get_context(context),
66-
'object': context['object'],
67+
'object': resolve_attr_path(context, self.accessor),
6768
}

0 commit comments

Comments
 (0)