From 7ad9e8a2fbd5e655143a7a40d2d4b41765dd1f4d Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Wed, 1 Jan 2020 19:53:13 +0000 Subject: [PATCH] More informative error message --- netbox/dcim/forms.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 7fc50f54b..3c515152e 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -76,12 +76,14 @@ class InterfaceCommonForm: # Validate tagged VLANs; must be a global VLAN or in the same site else: - for tagged_vlan in tagged_vlans: - if tagged_vlan.site not in [self.cleaned_data['device'].site, None]: - raise forms.ValidationError({ - 'tagged_vlans': "The tagged VLAN ({}) must belong to the same site as the interface's parent " - "device/VM, or it must be global".format(tagged_vlan) - }) + valid_sites = [None, self.cleaned_data['device'].site] + invalid_vlans = [str(v) for v in tagged_vlans if v.site not in valid_sites] + + if invalid_vlans: + raise forms.ValidationError({ + 'tagged_vlans': "The tagged VLANs ({}) must belong to the same site as the interface's parent " + "device/VM, or they must be global".format(', '.join(invalid_vlans)) + }) class BulkRenameForm(forms.Form):