mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Closes #2986: Replace DeviceComponentManager with NaturalOrderingManager
This commit is contained in:
parent
ca56871aaa
commit
245a97176a
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
|
* [#2986](https://github.com/digitalocean/netbox/issues/2986) - Improve natural ordering of device components
|
||||||
* [#3070](https://github.com/digitalocean/netbox/issues/3070) - Add decommissioning status for devices
|
* [#3070](https://github.com/digitalocean/netbox/issues/3070) - Add decommissioning status for devices
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
@ -14,22 +14,6 @@ CHANNEL_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*:(\d{{1,9}})(\.\d{{1,9}})?$')
|
|||||||
VC_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*\.(\d{{1,9}})$') AS integer), 0)"
|
VC_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*\.(\d{{1,9}})$') AS integer), 0)"
|
||||||
|
|
||||||
|
|
||||||
class DeviceComponentManager(Manager):
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
|
|
||||||
queryset = super().get_queryset()
|
|
||||||
table_name = self.model._meta.db_table
|
|
||||||
sql = r"CONCAT(REGEXP_REPLACE({}.name, '\d+$', ''), LPAD(SUBSTRING({}.name FROM '\d+$'), 8, '0'))"
|
|
||||||
|
|
||||||
# Pad any trailing digits to effect natural sorting
|
|
||||||
return queryset.extra(
|
|
||||||
select={
|
|
||||||
'name_padded': sql.format(table_name, table_name),
|
|
||||||
}
|
|
||||||
).order_by('name_padded', 'pk')
|
|
||||||
|
|
||||||
|
|
||||||
class InterfaceQuerySet(QuerySet):
|
class InterfaceQuerySet(QuerySet):
|
||||||
|
|
||||||
def connectable(self):
|
def connectable(self):
|
||||||
|
@ -23,7 +23,7 @@ from utilities.utils import serialize_object, to_meters
|
|||||||
from .constants import *
|
from .constants import *
|
||||||
from .exceptions import LoopDetected
|
from .exceptions import LoopDetected
|
||||||
from .fields import ASNField, MACAddressField
|
from .fields import ASNField, MACAddressField
|
||||||
from .managers import DeviceComponentManager, InterfaceManager
|
from .managers import InterfaceManager
|
||||||
|
|
||||||
|
|
||||||
class ComponentTemplateModel(models.Model):
|
class ComponentTemplateModel(models.Model):
|
||||||
@ -1004,7 +1004,7 @@ class ConsolePortTemplate(ComponentTemplateModel):
|
|||||||
max_length=50
|
max_length=50
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1027,7 +1027,7 @@ class ConsoleServerPortTemplate(ComponentTemplateModel):
|
|||||||
max_length=50
|
max_length=50
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1050,7 +1050,7 @@ class PowerPortTemplate(ComponentTemplateModel):
|
|||||||
max_length=50
|
max_length=50
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1073,7 +1073,7 @@ class PowerOutletTemplate(ComponentTemplateModel):
|
|||||||
max_length=50
|
max_length=50
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1139,7 +1139,7 @@ class FrontPortTemplate(ComponentTemplateModel):
|
|||||||
validators=[MinValueValidator(1), MaxValueValidator(64)]
|
validators=[MinValueValidator(1), MaxValueValidator(64)]
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1188,7 +1188,7 @@ class RearPortTemplate(ComponentTemplateModel):
|
|||||||
validators=[MinValueValidator(1), MaxValueValidator(64)]
|
validators=[MinValueValidator(1), MaxValueValidator(64)]
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1211,7 +1211,7 @@ class DeviceBayTemplate(ComponentTemplateModel):
|
|||||||
max_length=50
|
max_length=50
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['device_type', 'name']
|
ordering = ['device_type', 'name']
|
||||||
@ -1742,7 +1742,7 @@ class ConsolePort(CableTermination, ComponentModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name']
|
csv_headers = ['device', 'name']
|
||||||
@ -1785,7 +1785,7 @@ class ConsoleServerPort(CableTermination, ComponentModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name']
|
csv_headers = ['device', 'name']
|
||||||
@ -1834,7 +1834,7 @@ class PowerPort(CableTermination, ComponentModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name']
|
csv_headers = ['device', 'name']
|
||||||
@ -1877,7 +1877,7 @@ class PowerOutlet(CableTermination, ComponentModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name']
|
csv_headers = ['device', 'name']
|
||||||
@ -2198,7 +2198,7 @@ class FrontPort(CableTermination, ComponentModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name', 'type', 'rear_port', 'rear_port_position', 'description']
|
csv_headers = ['device', 'name', 'type', 'rear_port', 'rear_port_position', 'description']
|
||||||
@ -2264,7 +2264,7 @@ class RearPort(CableTermination, ComponentModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name', 'type', 'positions', 'description']
|
csv_headers = ['device', 'name', 'type', 'positions', 'description']
|
||||||
@ -2311,7 +2311,7 @@ class DeviceBay(ComponentModel):
|
|||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = DeviceComponentManager()
|
objects = NaturalOrderingManager()
|
||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = ['device', 'name', 'installed_device']
|
csv_headers = ['device', 'name', 'installed_device']
|
||||||
|
Loading…
Reference in New Issue
Block a user