1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Misc cleanup

This commit is contained in:
jeremystretch
2022-07-12 12:30:07 -04:00
parent 53372a7471
commit 43b27cc052
14 changed files with 58 additions and 19 deletions

View File

@@ -1031,8 +1031,8 @@ class InterfacePoEModeChoices(ChoiceSet):
MODE_PSE = 'pse'
CHOICES = (
(MODE_PD, 'Powered device (PD)'),
(MODE_PSE, 'Power sourcing equipment (PSE)'),
(MODE_PD, 'PD'),
(MODE_PSE, 'PSE'),
)

View File

@@ -1073,13 +1073,15 @@ class InterfaceBulkEditForm(
choices=add_blank_choice(InterfacePoEModeChoices),
required=False,
initial='',
widget=StaticSelect()
widget=StaticSelect(),
label='PoE mode'
)
poe_type = forms.ChoiceField(
choices=add_blank_choice(InterfacePoETypeChoices),
required=False,
initial='',
widget=StaticSelect()
widget=StaticSelect(),
label='PoE type'
)
mark_connected = forms.NullBooleanField(
required=False,

View File

@@ -227,6 +227,10 @@ class PathEndpoint(models.Model):
# Return the path as a list of three-tuples (A termination(s), cable(s), B termination(s))
return list(zip(*[iter(path)] * 3))
@property
def path(self):
return self._path
@cached_property
def connected_endpoints(self):
"""

View File

@@ -1,3 +1,4 @@
import decimal
from collections import OrderedDict
import yaml
@@ -279,6 +280,12 @@ class DeviceType(NetBoxModel):
def clean(self):
super().clean()
# U height must be divisible by 0.5
if self.u_height % decimal.Decimal(0.5):
raise ValidationError({
'u_height': "U height must be in increments of 0.5 rack units."
})
# If editing an existing DeviceType to have a larger u_height, first validate that *all* instances of it have
# room to expand within their racks. This validation will impose a very high performance penalty when there are
# many instances to check, but increasing the u_height of a DeviceType should be a very rare occurrence.
@@ -811,7 +818,11 @@ class Device(NetBoxModel, ConfigContextModel):
'position': "Cannot select a rack position without assigning a rack.",
})
# Validate position/face combination
# Validate rack position and face
if self.position and self.position % decimal.Decimal(0.5):
raise ValidationError({
'position': "Position must be in increments of 0.5 rack units."
})
if self.position and not self.face:
raise ValidationError({
'face': "Must specify rack face when defining rack position.",

View File

@@ -260,13 +260,14 @@ class RackElevationSVG:
)
for ru in range(0, self.rack.u_height):
unit = ru + 1 if self.rack.desc_units else self.rack.u_height - ru
y_offset = RACK_ELEVATION_BORDER_WIDTH + ru * self.unit_height
text_coords = (
x_offset + self.unit_width / 2,
y_offset + self.unit_height / 2
)
link = Hyperlink(href=url_string.format(ru), target='_blank')
link = Hyperlink(href=url_string.format(unit), target='_blank')
link.add(Rect((x_offset, y_offset), (self.unit_width, self.unit_height), class_='slot'))
link.add(Text('add device', insert=text_coords, class_='add-device'))

View File

@@ -125,6 +125,7 @@ class LocationTable(TenancyColumnsMixin, NetBoxTable):
site = tables.Column(
linkify=True
)
status = columns.ChoiceFieldColumn()
rack_count = columns.LinkedCountColumn(
viewname='dcim:rack_list',
url_params={'location_id': 'pk'},