14033 move check to cable model clean

This commit is contained in:
Arthur 2023-10-17 07:21:14 -07:00
parent 77d205d65f
commit 002cb3c896
2 changed files with 6 additions and 6 deletions

View File

@ -103,10 +103,4 @@ def get_cable_form(a_type, b_type):
self.instance.a_terminations = self.cleaned_data['a_terminations']
self.instance.b_terminations = self.cleaned_data['b_terminations']
if a_type == b_type and self.instance.a_terminations and self.instance.b_terminations:
if self.instance.a_terminations.intersection(self.instance.b_terminations):
raise forms.ValidationError(
_("A and B terminations cannot connect to the same object.")
)
return _CableForm

View File

@ -180,6 +180,12 @@ class Cable(PrimaryModel):
if b_type not in COMPATIBLE_TERMINATION_TYPES.get(a_type):
raise ValidationError(f"Incompatible termination types: {a_type} and {b_type}")
if a_type == b_type:
if (set(self.a_terminations) & set(self.b_terminations)):
raise ValidationError(
_("A and B terminations cannot connect to the same object.")
)
# Run clean() on any new CableTerminations
for termination in self.a_terminations:
CableTermination(cable=self, cable_end='A', termination=termination).clean()