Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions netbox/dcim/forms/object_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ def __init__(self, *args, **kwargs):
)
self.fields['rear_port'].choices = choices

def clean(self):

# Check that the number of FrontPortTemplates to be created matches the selected number of RearPortTemplate
# positions
frontport_count = len(self.cleaned_data['name'])
rearport_count = len(self.cleaned_data['rear_port'])
if frontport_count != rearport_count:
raise forms.ValidationError({
'rear_port': _(
"The number of front port templates to be created ({frontport_count}) must match the selected "
"number of rear port positions ({rearport_count})."
).format(
frontport_count=frontport_count,
rearport_count=rearport_count
)
})

def get_iterative_data(self, iteration):

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

def clean(self):

# Check that the number of FrontPorts to be created matches the selected number of RearPort positions
frontport_count = len(self.cleaned_data['name'])
rearport_count = len(self.cleaned_data['rear_port'])
if frontport_count != rearport_count:
raise forms.ValidationError({
'rear_port': _(
"The number of front ports to be created ({frontport_count}) must match the selected number of "
"rear port positions ({rearport_count})."
).format(
frontport_count=frontport_count,
rearport_count=rearport_count
)
})

def get_iterative_data(self, iteration):

# Assign rear port and position from selected set
Expand Down