diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 94528336f..35fa923c5 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -11,6 +11,7 @@ * [#6740](https://github.com/netbox-community/netbox/issues/6740) - Add import button to VM interfaces list * [#6892](https://github.com/netbox-community/netbox/issues/6892) - Fix validation of unit ranges when creating a rack reservation * [#6902](https://github.com/netbox-community/netbox/issues/6902) - Populate device field when cloning device components +* [#6908](https://github.com/netbox-community/netbox/issues/6908) - Allow assignment of scope to VLAN groups upon import * [#6909](https://github.com/netbox-community/netbox/issues/6909) - Remove extraneous `site` column from VLAN group import form * [#6910](https://github.com/netbox-community/netbox/issues/6910) - Fix exception on invalid CSV import column name diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 673e090cb..d130c5895 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -11,9 +11,9 @@ from tenancy.forms import TenancyFilterForm, TenancyForm from tenancy.models import Tenant from utilities.forms import ( add_blank_choice, BootstrapMixin, BulkEditNullBooleanSelect, ContentTypeChoiceField, CSVChoiceField, - CSVModelChoiceField, DatePicker, DynamicModelChoiceField, DynamicModelMultipleChoiceField, ExpandableIPAddressField, - NumericArrayField, ReturnURLForm, SlugField, StaticSelect2, StaticSelect2Multiple, TagFilterField, - BOOLEAN_WITH_BLANK_CHOICES, + CSVContentTypeField, CSVModelChoiceField, DatePicker, DynamicModelChoiceField, DynamicModelMultipleChoiceField, + ExpandableIPAddressField, NumericArrayField, ReturnURLForm, SlugField, StaticSelect2, StaticSelect2Multiple, + TagFilterField, BOOLEAN_WITH_BLANK_CHOICES, ) from virtualization.models import Cluster, ClusterGroup, VirtualMachine, VMInterface from .choices import * @@ -1239,10 +1239,18 @@ class VLANGroupForm(BootstrapMixin, CustomFieldModelForm): class VLANGroupCSVForm(CustomFieldModelCSVForm): slug = SlugField() + scope_type = CSVContentTypeField( + queryset=ContentType.objects.filter(model__in=VLANGROUP_SCOPE_TYPES), + required=False, + label='Scope type (app & model)' + ) class Meta: model = VLANGroup fields = VLANGroup.csv_headers + labels = { + 'scope_id': 'Scope ID', + } class VLANGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): diff --git a/netbox/ipam/tests/test_views.py b/netbox/ipam/tests/test_views.py index 057f9383f..5a80fd5f1 100644 --- a/netbox/ipam/tests/test_views.py +++ b/netbox/ipam/tests/test_views.py @@ -333,10 +333,10 @@ class VLANGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase): } cls.csv_data = ( - "name,slug,description", - "VLAN Group 4,vlan-group-4,Fourth VLAN group", - "VLAN Group 5,vlan-group-5,Fifth VLAN group", - "VLAN Group 6,vlan-group-6,Sixth VLAN group", + f"name,slug,scope_type,scope_id,description", + f"VLAN Group 4,vlan-group-4,,,Fourth VLAN group", + f"VLAN Group 5,vlan-group-5,dcim.site,{sites[0].pk},Fifth VLAN group", + f"VLAN Group 6,vlan-group-6,dcim.site,{sites[1].pk},Sixth VLAN group", ) cls.bulk_edit_data = { diff --git a/netbox/utilities/forms/fields.py b/netbox/utilities/forms/fields.py index 7cb2cd705..233549e0e 100644 --- a/netbox/utilities/forms/fields.py +++ b/netbox/utilities/forms/fields.py @@ -269,6 +269,8 @@ class CSVContentTypeField(CSVModelChoiceField): return f'{value.app_label}.{value.model}' def to_python(self, value): + if not value: + return None try: app_label, model = value.split('.') except ValueError: