mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 04:42:22 -06:00
Validate position count on FrontPort & FrontPortTemplate
This commit is contained in:
@@ -585,6 +585,19 @@ class FrontPortTemplate(ModularComponentTemplateModel):
|
||||
verbose_name = _('front port template')
|
||||
verbose_name_plural = _('front port templates')
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
# Check that positions is greater than or equal to the number of associated RearPortTemplates
|
||||
if not self._state.adding:
|
||||
mapping_count = self.mappings.count()
|
||||
if self.positions < mapping_count:
|
||||
raise ValidationError({
|
||||
"positions": _(
|
||||
"The number of positions cannot be less than the number of mapped rear port templates ({count})"
|
||||
).format(count=mapping_count)
|
||||
})
|
||||
|
||||
def instantiate(self, **kwargs):
|
||||
return self.component_model(
|
||||
name=self.resolve_name(kwargs.get('module')),
|
||||
@@ -638,7 +651,7 @@ class RearPortTemplate(ModularComponentTemplateModel):
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
# Check that positions count is greater than or equal to the number of associated FrontPortTemplates
|
||||
# Check that positions is greater than or equal to the number of associated FrontPortTemplates
|
||||
if not self._state.adding:
|
||||
mapping_count = self.mappings.count()
|
||||
if self.positions < mapping_count:
|
||||
|
||||
@@ -1132,6 +1132,19 @@ class FrontPort(ModularComponentModel, CabledObjectModel, TrackingModelMixin):
|
||||
verbose_name = _('front port')
|
||||
verbose_name_plural = _('front ports')
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
# Check that positions is greater than or equal to the number of associated RearPorts
|
||||
if not self._state.adding:
|
||||
mapping_count = self.mappings.count()
|
||||
if self.positions < mapping_count:
|
||||
raise ValidationError({
|
||||
"positions": _(
|
||||
"The number of positions cannot be less than the number of mapped rear ports ({count})"
|
||||
).format(count=mapping_count)
|
||||
})
|
||||
|
||||
|
||||
class RearPort(ModularComponentModel, CabledObjectModel, TrackingModelMixin):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user