Fixes #13033: add formatted speed column to Interfaces

This commit is contained in:
Matej Vadnjal 2023-07-26 18:07:44 +02:00
parent 0f0cf683c4
commit 59e657867c
3 changed files with 28 additions and 1 deletions

View File

@ -1,4 +1,5 @@
from .cables import * from .cables import *
from .columns import *
from .connections import * from .connections import *
from .devices import * from .devices import *
from .devicetypes import * from .devicetypes import *

View File

@ -0,0 +1,21 @@
import django_tables2 as tables
__all__ = (
'SpeedColumn',
)
class SpeedColumn(tables.TemplateColumn):
"""
Humanize the speed in the column view
"""
template_code = """
{% load helpers %}
{{ value|humanize_speed|placeholder }}
"""
def __init__(self, *args, **kwargs):
super().__init__(template_code=self.template_code, *args, **kwargs)
def value(self, value, **kwargs):
return super().value(value=value, **kwargs) if value else None

View File

@ -5,6 +5,7 @@ from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
from netbox.tables import NetBoxTable, columns from netbox.tables import NetBoxTable, columns
from .columns import *
from .template_code import * from .template_code import *
__all__ = ( __all__ = (
@ -545,6 +546,10 @@ class InterfaceTable(ModularDeviceComponentTable, BaseInterfaceTable, PathEndpoi
} }
) )
mgmt_only = columns.BooleanColumn() mgmt_only = columns.BooleanColumn()
speed_formatted = SpeedColumn(
accessor=Accessor('speed'),
verbose_name='Speed'
)
wireless_link = tables.Column( wireless_link = tables.Column(
linkify=True linkify=True
) )
@ -568,7 +573,7 @@ class InterfaceTable(ModularDeviceComponentTable, BaseInterfaceTable, PathEndpoi
model = models.Interface model = models.Interface
fields = ( fields = (
'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'enabled', 'type', 'mgmt_only', 'mtu',
'speed', 'duplex', 'mode', 'mac_address', 'wwn', 'poe_mode', 'poe_type', 'rf_role', 'rf_channel', 'speed', 'speed_formatted', 'duplex', 'mode', 'mac_address', 'wwn', 'poe_mode', 'poe_type', 'rf_role', 'rf_channel',
'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'description', 'mark_connected', 'cable', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'description', 'mark_connected', 'cable',
'cable_color', 'wireless_link', 'wireless_lans', 'link_peer', 'connection', 'tags', 'vdcs', 'vrf', 'l2vpn', 'cable_color', 'wireless_link', 'wireless_lans', 'link_peer', 'connection', 'tags', 'vdcs', 'vrf', 'l2vpn',
'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'created', 'last_updated', 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'created', 'last_updated',