From b21e45a1b522e756edd46a622aed529d130cef3a Mon Sep 17 00:00:00 2001 From: Dillon Henschen Date: Sat, 3 Jun 2023 17:40:22 -0400 Subject: [PATCH] Move save logic to model to reduce redundancy of both import and edit fields --- netbox/ipam/forms/bulk_import.py | 12 ------------ netbox/ipam/models/vlans.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index f4e1536df..fd0b315a0 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -408,18 +408,6 @@ 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( diff --git a/netbox/ipam/models/vlans.py b/netbox/ipam/models/vlans.py index 0d07eb12a..7bcfba440 100644 --- a/netbox/ipam/models/vlans.py +++ b/netbox/ipam/models/vlans.py @@ -230,6 +230,18 @@ class VLAN(PrimaryModel): f"{self.group}" }) + def save(self, *args, **kwargs): + # Implicitly set the Assignment Type based on the validated assignment of group or site + # Do this on the model to reduce redundancy of doing this in both Bulk Edit and Bulk Import + if self.group: + self.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.site: + self.assignment_type = VLANAssignmentTypeChoices.SITE + + super().save(*args, **kwargs) + def get_status_color(self): return VLANStatusChoices.colors.get(self.status)