mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Make sure we bail out if field validation failed when importing modules * Tweak form validation logic Co-authored-by: jeremystretch <jstretch@ns1.com>
This commit is contained in:
@ -56,8 +56,8 @@ class ModuleCommonForm(forms.Form):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
replicate_components = self.cleaned_data.get("replicate_components")
|
replicate_components = self.cleaned_data.get('replicate_components')
|
||||||
adopt_components = self.cleaned_data.get("adopt_components")
|
adopt_components = self.cleaned_data.get('adopt_components')
|
||||||
device = self.cleaned_data.get('device')
|
device = self.cleaned_data.get('device')
|
||||||
module_type = self.cleaned_data.get('module_type')
|
module_type = self.cleaned_data.get('module_type')
|
||||||
module_bay = self.cleaned_data.get('module_bay')
|
module_bay = self.cleaned_data.get('module_bay')
|
||||||
@ -65,8 +65,9 @@ class ModuleCommonForm(forms.Form):
|
|||||||
if adopt_components:
|
if adopt_components:
|
||||||
self.instance._adopt_components = True
|
self.instance._adopt_components = True
|
||||||
|
|
||||||
# Bail out if we are not installing a new module or if we are not replicating components
|
# Bail out if we are not installing a new module or if we are not replicating components (or if
|
||||||
if self.instance.pk or not replicate_components:
|
# validation has already failed)
|
||||||
|
if self.errors or self.instance.pk or not replicate_components:
|
||||||
self.instance._disable_replication = True
|
self.instance._disable_replication = True
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -961,7 +961,7 @@ class Module(PrimaryModel, ConfigContextModel):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.module_bay.device != self.device:
|
if hasattr(self, "module_bay") and (self.module_bay.device != self.device):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
f"Module must be installed within a module bay belonging to the assigned device ({self.device})."
|
f"Module must be installed within a module bay belonging to the assigned device ({self.device})."
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user