Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Nov 15, 2024
1 parent d1802bf commit 8a42c72
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
7 changes: 6 additions & 1 deletion netbox/dcim/tables/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ class Meta(CableTerminationTable.Meta, DeviceComponentTable.Meta):


class BaseInterfaceTable(NetBoxTable):
name = tables.Column(
verbose_name=_('Name'),
linkify=True,
order_by=('_name',)
)
enabled = columns.BooleanColumn(
verbose_name=_('Enabled'),
)
Expand Down Expand Up @@ -591,7 +596,7 @@ def value_tagged_vlans(self, value):
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={
Expand Down
4 changes: 4 additions & 0 deletions netbox/dcim/tables/devicetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class Meta(ComponentTemplateTable.Meta):


class InterfaceTemplateTable(ComponentTemplateTable):
name = tables.Column(
verbose_name=_('Name'),
order_by=('_name',)
)
enabled = columns.BooleanColumn(
verbose_name=_('Enabled'),
)
Expand Down
3 changes: 1 addition & 2 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,7 @@ def get(self, request):
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)
Expand Down
3 changes: 1 addition & 2 deletions netbox/utilities/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 5 additions & 11 deletions netbox/virtualization/models/virtualmachines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -405,11 +404,6 @@ def l2vpn_termination(self):


class VirtualDisk(ComponentModel, TrackingModelMixin):
name = models.CharField(
verbose_name=_('name'),
max_length=64,
db_collation="natural_sort"
)
size = models.PositiveIntegerField(
verbose_name=_('size (MB)'),
)
Expand Down

0 comments on commit 8a42c72

Please sign in to comment.