mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 03:56:53 -06:00
Fixes #307: Validate device type assignment during import validation
This commit is contained in:
parent
f301af5ecd
commit
5def0e91d7
@ -624,6 +624,10 @@ class Device(CreatedUpdatedModel):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
# Validate device type assignment
|
||||||
|
if not hasattr(self, 'device_type'):
|
||||||
|
raise ValidationError("Must specify device type.")
|
||||||
|
|
||||||
# Child devices cannot be assigned to a rack face/unit
|
# Child devices cannot be assigned to a rack face/unit
|
||||||
if self.device_type.is_child_device and (self.face is not None or self.position):
|
if self.device_type.is_child_device and (self.face is not None or self.position):
|
||||||
raise ValidationError("Child device types cannot be assigned a rack face or position.")
|
raise ValidationError("Child device types cannot be assigned a rack face or position.")
|
||||||
@ -633,10 +637,7 @@ class Device(CreatedUpdatedModel):
|
|||||||
raise ValidationError("Must specify rack face with rack position.")
|
raise ValidationError("Must specify rack face with rack position.")
|
||||||
|
|
||||||
# Validate rack space
|
# Validate rack space
|
||||||
try:
|
|
||||||
rack_face = self.face if not self.device_type.is_full_depth else None
|
rack_face = self.face if not self.device_type.is_full_depth else None
|
||||||
except DeviceType.DoesNotExist:
|
|
||||||
raise ValidationError("Must specify device type.")
|
|
||||||
exclude_list = [self.pk] if self.pk else []
|
exclude_list = [self.pk] if self.pk else []
|
||||||
try:
|
try:
|
||||||
available_units = self.rack.get_available_units(u_height=self.device_type.u_height, rack_face=rack_face,
|
available_units = self.rack.get_available_units(u_height=self.device_type.u_height, rack_face=rack_face,
|
||||||
|
Loading…
Reference in New Issue
Block a user