From 563c10501a528d4787c4b8e1c058a9f3a775f6fa Mon Sep 17 00:00:00 2001 From: Dillon Henschen Date: Sat, 3 Jun 2023 16:16:21 -0400 Subject: [PATCH] 11891: Implicitly Set Assignment Type during VLAN Import --- netbox/ipam/forms/bulk_import.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index fd0b315a0..f4e1536df 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -408,6 +408,18 @@ class VLANImportForm(NetBoxModelImportForm): model = VLAN fields = ('site', 'group', 'vid', 'name', 'tenant', 'status', 'role', 'description', 'comments', 'tags') + def save(self, *args, **kwargs): + + # Implicitly set the Assignment Type based on the validated assignment of group or site + if self.cleaned_data.get('group'): + self.instance.assignment_type = VLANAssignmentTypeChoices.VLAN_GROUP + + # elif to prefer the Assignment Type of VLAN_GROUP if the VLAN Group site scope is also set. + elif self.cleaned_data.get('site'): + self.instance.assignment_type = VLANAssignmentTypeChoices.SITE + + return super().save(*args, **kwargs) + class ServiceTemplateImportForm(NetBoxModelImportForm): protocol = CSVChoiceField(