Perform Rack object validation of u_height and starting_unit on rack_type if present

This commit is contained in:
Brian Tiemann 2025-01-14 14:46:31 -05:00
parent a75fa53d4d
commit 7a9a684ece

View File

@ -377,19 +377,23 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, RackBase):
# Validate that Rack is tall enough to house the highest mounted Device
if top_device := mounted_devices.last():
min_height = top_device.position + top_device.device_type.u_height - self.starting_unit
if self.u_height < min_height:
effective_u_height = self.rack_type.u_height if self.rack_type else self.u_height
if effective_u_height < min_height:
field = 'rack_type' if self.rack_type else 'u_height'
raise ValidationError({
'u_height': _(
field: _(
"Rack must be at least {min_height}U tall to house currently installed devices."
).format(min_height=min_height)
})
# Validate that the Rack's starting unit is less than or equal to the position of the lowest mounted Device
if last_device := mounted_devices.first():
if self.starting_unit > last_device.position:
effective_starting_unit = self.rack_type.starting_unit if self.rack_type else self.starting_unit
if effective_starting_unit > last_device.position:
field = 'rack_type' if self.rack_type else 'starting_unit'
raise ValidationError({
'starting_unit': _("Rack unit numbering must begin at {position} or less to house "
"currently installed devices.").format(position=last_device.position)
field: _("Rack unit numbering must begin at {position} or less to house "
"currently installed devices.").format(position=last_device.position)
})
# Validate that Rack was assigned a Location of its same site, if applicable