mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Fixes #2616: Convert Rack outer_unit and Cable length_unit to integer-based choice fields
This commit is contained in:
parent
a1a9396287
commit
d1cd366dc9
@ -44,6 +44,7 @@ NetBox now supports modeling physical cables for console, power, and interface c
|
|||||||
|
|
||||||
* [#2622](https://github.com/digitalocean/netbox/issues/2622) - Enable filtering cables by multiple types/colors
|
* [#2622](https://github.com/digitalocean/netbox/issues/2622) - Enable filtering cables by multiple types/colors
|
||||||
* [#2624](https://github.com/digitalocean/netbox/issues/2624) - Delete associated content type and permissions when removing InterfaceConnection model
|
* [#2624](https://github.com/digitalocean/netbox/issues/2624) - Delete associated content type and permissions when removing InterfaceConnection model
|
||||||
|
* [#2616](https://github.com/digitalocean/netbox/issues/2616) - Convert Rack `outer_unit` and Cable `length_unit` to integer-based choice fields
|
||||||
|
|
||||||
## API Changes
|
## API Changes
|
||||||
|
|
||||||
|
@ -360,11 +360,11 @@ COMPATIBLE_TERMINATION_TYPES = {
|
|||||||
'circuittermination': ['interface', 'frontport', 'rearport'],
|
'circuittermination': ['interface', 'frontport', 'rearport'],
|
||||||
}
|
}
|
||||||
|
|
||||||
LENGTH_UNIT_METER = 'm'
|
LENGTH_UNIT_METER = 1200
|
||||||
LENGTH_UNIT_CENTIMETER = 'cm'
|
LENGTH_UNIT_CENTIMETER = 1100
|
||||||
LENGTH_UNIT_MILLIMETER = 'mm'
|
LENGTH_UNIT_MILLIMETER = 1000
|
||||||
LENGTH_UNIT_FOOT = 'ft'
|
LENGTH_UNIT_FOOT = 2100
|
||||||
LENGTH_UNIT_INCH = 'in'
|
LENGTH_UNIT_INCH = 2000
|
||||||
CABLE_LENGTH_UNIT_CHOICES = (
|
CABLE_LENGTH_UNIT_CHOICES = (
|
||||||
(LENGTH_UNIT_METER, 'Meters'),
|
(LENGTH_UNIT_METER, 'Meters'),
|
||||||
(LENGTH_UNIT_CENTIMETER, 'Centimeters'),
|
(LENGTH_UNIT_CENTIMETER, 'Centimeters'),
|
||||||
|
@ -166,7 +166,7 @@ class Migration(migrations.Migration):
|
|||||||
('label', models.CharField(blank=True, max_length=100)),
|
('label', models.CharField(blank=True, max_length=100)),
|
||||||
('color', utilities.fields.ColorField(blank=True, max_length=6)),
|
('color', utilities.fields.ColorField(blank=True, max_length=6)),
|
||||||
('length', models.PositiveSmallIntegerField(blank=True, null=True)),
|
('length', models.PositiveSmallIntegerField(blank=True, null=True)),
|
||||||
('length_unit', models.CharField(blank=True, max_length=2)),
|
('length_unit', models.PositiveSmallIntegerField(blank=True, null=True)),
|
||||||
('_abs_length', models.DecimalField(blank=True, decimal_places=4, max_digits=10, null=True)),
|
('_abs_length', models.DecimalField(blank=True, decimal_places=4, max_digits=10, null=True)),
|
||||||
('termination_a_type', models.ForeignKey(limit_choices_to={'model__in': ['consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontport', 'rearport']}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
|
('termination_a_type', models.ForeignKey(limit_choices_to={'model__in': ['consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontport', 'rearport']}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
|
||||||
('termination_b_type', models.ForeignKey(limit_choices_to={'model__in': ['consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontport', 'rearport']}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
|
('termination_b_type', models.ForeignKey(limit_choices_to={'model__in': ['consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontport', 'rearport']}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
|
||||||
|
@ -28,7 +28,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='rack',
|
model_name='rack',
|
||||||
name='outer_unit',
|
name='outer_unit',
|
||||||
field=models.CharField(blank=True, max_length=2),
|
field=models.PositiveSmallIntegerField(blank=True, null=True),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='rack',
|
model_name='rack',
|
||||||
|
@ -511,10 +511,10 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
outer_unit = models.CharField(
|
outer_unit = models.PositiveSmallIntegerField(
|
||||||
choices=RACK_DIMENSION_UNIT_CHOICES,
|
choices=RACK_DIMENSION_UNIT_CHOICES,
|
||||||
max_length=2,
|
blank=True,
|
||||||
blank=True
|
null=True
|
||||||
)
|
)
|
||||||
comments = models.TextField(
|
comments = models.TextField(
|
||||||
blank=True
|
blank=True
|
||||||
@ -552,10 +552,10 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
# Validate outer dimensions and unit
|
# Validate outer dimensions and unit
|
||||||
if (self.outer_width or self.outer_depth) and not self.outer_unit:
|
if (self.outer_width is not None or self.outer_depth is not None) and self.outer_unit is None:
|
||||||
raise ValidationError("Must specify a unit when setting an outer width/depth")
|
raise ValidationError("Must specify a unit when setting an outer width/depth")
|
||||||
else:
|
else:
|
||||||
self.outer_unit = ''
|
self.outer_unit = None
|
||||||
|
|
||||||
if self.pk:
|
if self.pk:
|
||||||
# Validate that Rack is tall enough to house the installed Devices
|
# Validate that Rack is tall enough to house the installed Devices
|
||||||
@ -2495,10 +2495,10 @@ class Cable(ChangeLoggedModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
length_unit = models.CharField(
|
length_unit = models.PositiveSmallIntegerField(
|
||||||
choices=CABLE_LENGTH_UNIT_CHOICES,
|
choices=CABLE_LENGTH_UNIT_CHOICES,
|
||||||
max_length=2,
|
blank=True,
|
||||||
blank=True
|
null=True
|
||||||
)
|
)
|
||||||
# Stores the normalized length (in meters) for database ordering
|
# Stores the normalized length (in meters) for database ordering
|
||||||
_abs_length = models.DecimalField(
|
_abs_length = models.DecimalField(
|
||||||
@ -2584,10 +2584,10 @@ class Cable(ChangeLoggedModel):
|
|||||||
raise ValidationError("Cannot connect to a virtual interface")
|
raise ValidationError("Cannot connect to a virtual interface")
|
||||||
|
|
||||||
# Validate length and length_unit
|
# Validate length and length_unit
|
||||||
if self.length and not self.length_unit:
|
if self.length is not None and self.length_unit is None:
|
||||||
raise ValidationError("Must specify a unit when setting a cable length")
|
raise ValidationError("Must specify a unit when setting a cable length")
|
||||||
if self.length_unit and self.length is None:
|
else:
|
||||||
self.length_unit = ''
|
self.length_unit = None
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user