mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #1275: Raise validation error on prefix import when multiple VLANs are found
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import MultipleObjectsReturned
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
|
||||||
from dcim.models import Site, Rack, Device, Interface
|
from dcim.models import Site, Rack, Device, Interface
|
||||||
@ -301,6 +302,10 @@ class PrefixCSVForm(forms.ModelForm):
|
|||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
raise forms.ValidationError("Global VLAN {} not found in group {}".format(vlan_vid, vlan_group))
|
raise forms.ValidationError("Global VLAN {} not found in group {}".format(vlan_vid, vlan_group))
|
||||||
|
except MultipleObjectsReturned:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
"Multiple VLANs with VID {} found in group {}".format(vlan_vid, vlan_group)
|
||||||
|
)
|
||||||
elif vlan_vid:
|
elif vlan_vid:
|
||||||
try:
|
try:
|
||||||
self.instance.vlan = VLAN.objects.get(site=site, group__isnull=True, vid=vlan_vid)
|
self.instance.vlan = VLAN.objects.get(site=site, group__isnull=True, vid=vlan_vid)
|
||||||
@ -309,6 +314,8 @@ class PrefixCSVForm(forms.ModelForm):
|
|||||||
raise forms.ValidationError("VLAN {} not found in site {}".format(vlan_vid, site))
|
raise forms.ValidationError("VLAN {} not found in site {}".format(vlan_vid, site))
|
||||||
else:
|
else:
|
||||||
raise forms.ValidationError("Global VLAN {} not found".format(vlan_vid))
|
raise forms.ValidationError("Global VLAN {} not found".format(vlan_vid))
|
||||||
|
except MultipleObjectsReturned:
|
||||||
|
raise forms.ValidationError("Multiple VLANs with VID {} found".format(vlan_vid))
|
||||||
|
|
||||||
|
|
||||||
class PrefixBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
class PrefixBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
||||||
|
Reference in New Issue
Block a user