From 8a42c72ca46d36bc0e41c78855a9ae82a98efaa0 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 15 Nov 2024 09:04:52 -0500 Subject: [PATCH] Misc cleanup --- netbox/dcim/tables/devices.py | 7 ++++++- netbox/dcim/tables/devicetypes.py | 4 ++++ netbox/dcim/views.py | 3 +-- netbox/utilities/fields.py | 3 +-- netbox/virtualization/models/virtualmachines.py | 16 +++++----------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 41a45829e..b7634626d 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -544,6 +544,11 @@ class DevicePowerOutletTable(PowerOutletTable): class BaseInterfaceTable(NetBoxTable): + name = tables.Column( + verbose_name=_('Name'), + linkify=True, + order_by=('_name',) + ) enabled = columns.BooleanColumn( verbose_name=_('Enabled'), ) @@ -591,7 +596,7 @@ class BaseInterfaceTable(NetBoxTable): return ",".join([str(obj) for obj in value.all()]) -class InterfaceTable(ModularDeviceComponentTable, BaseInterfaceTable, PathEndpointTable): +class InterfaceTable(BaseInterfaceTable, ModularDeviceComponentTable, PathEndpointTable): device = tables.Column( verbose_name=_('Device'), linkify={ diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index d9e572556..a7f8f08e8 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -218,6 +218,10 @@ class PowerOutletTemplateTable(ComponentTemplateTable): class InterfaceTemplateTable(ComponentTemplateTable): + name = tables.Column( + verbose_name=_('Name'), + order_by=('_name',) + ) enabled = columns.BooleanColumn( verbose_name=_('Enabled'), ) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 03915386e..7a5a771a9 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -688,8 +688,7 @@ class RackElevationListView(generic.ObjectListView): sort = request.GET.get('sort', 'name') if sort not in ORDERING_CHOICES: sort = 'name' - sort_field = sort # Use natural ordering - racks = racks.order_by(sort_field) + racks = racks.order_by(sort) # Pagination per_page = get_paginate_count(request) diff --git a/netbox/utilities/fields.py b/netbox/utilities/fields.py index c4ea13bc9..1d16a1d3f 100644 --- a/netbox/utilities/fields.py +++ b/netbox/utilities/fields.py @@ -5,7 +5,6 @@ from django.db import models from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ -from utilities.ordering import naturalize_interface from .forms.widgets import ColorSelect from .validators import ColorValidator @@ -40,7 +39,7 @@ class NaturalOrderingField(models.CharField): """ description = "Stores a representation of its target field suitable for natural ordering" - def __init__(self, target_field, naturalize_function=naturalize_interface, *args, **kwargs): + def __init__(self, target_field, naturalize_function, *args, **kwargs): self.target_field = target_field self.naturalize_function = naturalize_function super().__init__(*args, **kwargs) diff --git a/netbox/virtualization/models/virtualmachines.py b/netbox/virtualization/models/virtualmachines.py index 7e048b950..ebfb2d6c5 100644 --- a/netbox/virtualization/models/virtualmachines.py +++ b/netbox/virtualization/models/virtualmachines.py @@ -267,6 +267,11 @@ class ComponentModel(NetBoxModel): on_delete=models.CASCADE, related_name='%(class)ss' ) + name = models.CharField( + verbose_name=_('name'), + max_length=64, + db_collation="natural_sort" + ) description = models.CharField( verbose_name=_('description'), max_length=200, @@ -311,12 +316,6 @@ class VMInterface(ComponentModel, BaseInterface, TrackingModelMixin): on_delete=models.CASCADE, related_name='interfaces' # Override ComponentModel ) - _name = NaturalOrderingField( - target_field='name', - naturalize_function=naturalize_interface, - max_length=100, - blank=True - ) ip_addresses = GenericRelation( to='ipam.IPAddress', content_type_field='assigned_object_type', @@ -405,11 +404,6 @@ class VMInterface(ComponentModel, BaseInterface, TrackingModelMixin): class VirtualDisk(ComponentModel, TrackingModelMixin): - name = models.CharField( - verbose_name=_('name'), - max_length=64, - db_collation="natural_sort" - ) size = models.PositiveIntegerField( verbose_name=_('size (MB)'), )