Skip to content

Commit 6900097

Browse files
committed
Fixes #14117: Validate the number of front ports to be created
1 parent 5000564 commit 6900097

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

netbox/dcim/forms/object_create.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ def __init__(self, *args, **kwargs):
151151
)
152152
self.fields['rear_port'].choices = choices
153153

154+
def clean(self):
155+
156+
# Check that the number of FrontPortTemplates to be created matches the selected number of RearPortTemplate
157+
# positions
158+
frontport_count = len(self.cleaned_data['name'])
159+
rearport_count = len(self.cleaned_data['rear_port'])
160+
if frontport_count != rearport_count:
161+
raise forms.ValidationError({
162+
'rear_port': _(
163+
"The number of front port templates to be created ({frontport_count}) must match the selected "
164+
"number of rear port positions ({rearport_count})."
165+
).format(
166+
frontport_count=frontport_count,
167+
rearport_count=rearport_count
168+
)
169+
})
170+
154171
def get_iterative_data(self, iteration):
155172

156173
# Assign rear port and position from selected set
@@ -291,6 +308,22 @@ def __init__(self, *args, **kwargs):
291308
)
292309
self.fields['rear_port'].choices = choices
293310

311+
def clean(self):
312+
313+
# Check that the number of FrontPorts to be created matches the selected number of RearPort positions
314+
frontport_count = len(self.cleaned_data['name'])
315+
rearport_count = len(self.cleaned_data['rear_port'])
316+
if frontport_count != rearport_count:
317+
raise forms.ValidationError({
318+
'rear_port': _(
319+
"The number of front ports to be created ({frontport_count}) must match the selected number of "
320+
"rear port positions ({rearport_count})."
321+
).format(
322+
frontport_count=frontport_count,
323+
rearport_count=rearport_count
324+
)
325+
})
326+
294327
def get_iterative_data(self, iteration):
295328

296329
# Assign rear port and position from selected set

0 commit comments

Comments
 (0)