Skip to content
Closed
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
15 changes: 15 additions & 0 deletions netbox/dcim/forms/object_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def clean(self):
).format(value_count=value_count, pattern_count=pattern_count)
}, code='label_pattern_mismatch')

if hasattr(self, 'get_iterative_data'):
object_name, iterative_limit = self.get_iterative_item_limit()
if pattern_count > iterative_limit:
raise forms.ValidationError({
field_name: _(
"The provided pattern specifies {pattern_count} values but there are not enough {object_name} selected to assign to."
).format(pattern_count=pattern_count, object_name=object_name)
}, code='label_pattern_mismatch')


#
# Device component templates
Expand Down Expand Up @@ -161,6 +170,9 @@ def get_iterative_data(self, iteration):
'rear_port_position': int(position),
}

def get_iterative_item_limit(self):
return _('rear ports'), len(self.cleaned_data['rear_port'])


class RearPortTemplateCreateForm(ComponentCreateForm, model_forms.RearPortTemplateForm):

Expand Down Expand Up @@ -301,6 +313,9 @@ def get_iterative_data(self, iteration):
'rear_port_position': int(position),
}

def get_iterative_item_limit(self):
return _('rear ports'), len(self.cleaned_data['rear_port'])


class RearPortCreateForm(ComponentCreateForm, model_forms.RearPortForm):

Expand Down