diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 95e459a47..d77b2cc88 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -12,7 +12,7 @@ from utilities.tables import ( ) from .template_code import ( CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, FRONTPORT_BUTTONS, - INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS, + INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS, REARPORT_BUTTONS, ) __all__ = ( @@ -25,6 +25,7 @@ __all__ = ( 'DeviceImportTable', 'DevicePowerPortTable', 'DevicePowerOutletTable', + 'DeviceRearPortTable', 'DeviceRoleTable', 'DeviceTable', 'FrontPortTable', @@ -458,6 +459,31 @@ class RearPortTable(DeviceComponentTable, CableTerminationTable): default_columns = ('pk', 'device', 'name', 'label', 'type', 'description') +class DeviceRearPortTable(RearPortTable): + name = tables.TemplateColumn( + template_code=' ' + '{{ value }}' + ) + actions = ButtonsColumn( + model=RearPort, + buttons=('edit', 'delete'), + prepend_template=REARPORT_BUTTONS + ) + + class Meta(DeviceComponentTable.Meta): + model = RearPort + fields = ( + 'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'connection', 'tags', + 'actions', + ) + default_columns = ( + 'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'actions', + ) + row_attrs = { + 'class': lambda record: record.cable.get_status_class() if record.cable else '' + } + + class DeviceBayTable(DeviceComponentTable): installed_device = tables.Column( linkify=True diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index e7182e1da..9d717f794 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -157,3 +157,21 @@ FRONTPORT_BUTTONS = """ {% endif %} """ + +REARPORT_BUTTONS = """ +{% if record.cable %} + {% include 'dcim/inc/cable_toggle_buttons.html' with cable=record.cable %} +{% elif perms.dcim.add_cable %} + + + + +{% endif %} +""" diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 1056a8078..c09b6cca5 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1067,6 +1067,9 @@ class DeviceView(ObjectView): # Rear ports rearports = RearPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related('cable') + rearport_table = tables.DeviceRearPortTable(rearports, orderable=False) + if request.user.has_perm('dcim.change_rearport') or request.user.has_perm('dcim.delete_rearport'): + rearport_table.columns.show('pk') # Device bays devicebays = DeviceBay.objects.restrict(request.user, 'view').filter(device=device).prefetch_related( @@ -1101,7 +1104,7 @@ class DeviceView(ObjectView): 'poweroutlet_table': poweroutlet_table, 'interfaces': interfaces, 'frontport_table': frontport_table, - 'rearports': rearports, + 'rearport_table': rearport_table, 'devicebays': devicebays, 'inventoryitems': inventoryitems, 'services': services, diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 94f66b345..693f3ccf8 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -128,7 +128,7 @@ Front Ports {% badge frontport_table.rows|length %}
  • - Rear Ports {% badge rearports|length %} + Rear Ports {% badge rearport_table.rows|length %}
  • Console Ports {% badge consoleport_table.rows|length %} @@ -557,7 +557,7 @@ {% include 'responsive_table.html' with table=frontport_table %}