mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Fixes #6908: Allow assignment of scope to VLAN groups upon import
This commit is contained in:
parent
7bcebd5b0f
commit
1bb596fc7e
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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 = {
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user