mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-09 05:12:18 -06:00
Clean up validation logic
This commit is contained in:
@@ -220,18 +220,31 @@ class CabledObjectModel(models.Model):
|
|||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"cable_end": _("Must specify cable end (A or B) when attaching a cable.")
|
"cable_end": _("Must specify cable end (A or B) when attaching a cable.")
|
||||||
})
|
})
|
||||||
if self.cable_end and not self.cable:
|
if self.cable_connector and not self.cable_positions:
|
||||||
|
raise ValidationError({
|
||||||
|
"cable_positions": _("Must specify position(s) when specifying a cable connector.")
|
||||||
|
})
|
||||||
|
if self.cable_positions and not self.cable_connector:
|
||||||
|
raise ValidationError({
|
||||||
|
"cable_positions": _("Cable positions cannot be set without a cable connector.")
|
||||||
|
})
|
||||||
|
if self.mark_connected:
|
||||||
|
raise ValidationError({
|
||||||
|
"mark_connected": _("Cannot mark as connected with a cable attached.")
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
if self.cable_end:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"cable_end": _("Cable end must not be set without a cable.")
|
"cable_end": _("Cable end must not be set without a cable.")
|
||||||
})
|
})
|
||||||
if self.cable_positions and not self.cable:
|
if self.cable_connector:
|
||||||
|
raise ValidationError({
|
||||||
|
"cable_connector": _("Cable connector must not be set without a cable.")
|
||||||
|
})
|
||||||
|
if self.cable_positions:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"cable_positions": _("Cable termination positions must not be set without a cable.")
|
"cable_positions": _("Cable termination positions must not be set without a cable.")
|
||||||
})
|
})
|
||||||
if self.mark_connected and self.cable:
|
|
||||||
raise ValidationError({
|
|
||||||
"mark_connected": _("Cannot mark as connected with a cable attached.")
|
|
||||||
})
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def link(self):
|
def link(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user