mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
Fixes #13843: Fix scope assignment for VLAN groups during bulk edit
This commit is contained in:
parent
bd1cbce2b3
commit
4fe02a7be5
@ -431,6 +431,10 @@ class VLANGroupBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
queryset=ContentType.objects.filter(model__in=VLANGROUP_SCOPE_TYPES),
|
queryset=ContentType.objects.filter(model__in=VLANGROUP_SCOPE_TYPES),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
scope_id = forms.IntegerField(
|
||||||
|
required=False,
|
||||||
|
widget=forms.HiddenInput()
|
||||||
|
)
|
||||||
region = DynamicModelChoiceField(
|
region = DynamicModelChoiceField(
|
||||||
label=_('Region'),
|
label=_('Region'),
|
||||||
queryset=Region.objects.all(),
|
queryset=Region.objects.all(),
|
||||||
@ -488,6 +492,19 @@ class VLANGroupBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
)
|
)
|
||||||
nullable_fields = ('description',)
|
nullable_fields = ('description',)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
# Assign scope based on scope_type
|
||||||
|
if self.cleaned_data.get('scope_type'):
|
||||||
|
scope_field = self.cleaned_data['scope_type'].model
|
||||||
|
if scope_obj := self.cleaned_data.get(scope_field):
|
||||||
|
self.cleaned_data['scope_id'] = scope_obj.pk
|
||||||
|
self.changed_data.append('scope_id')
|
||||||
|
else:
|
||||||
|
self.cleaned_data.pop('scope_type')
|
||||||
|
self.changed_data.remove('scope_type')
|
||||||
|
|
||||||
|
|
||||||
class VLANBulkEditForm(NetBoxModelBulkEditForm):
|
class VLANBulkEditForm(NetBoxModelBulkEditForm):
|
||||||
region = DynamicModelChoiceField(
|
region = DynamicModelChoiceField(
|
||||||
|
@ -3,6 +3,7 @@ import re
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.contrib.contenttypes.fields import GenericRel
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist, ValidationError
|
from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist, ValidationError
|
||||||
from django.db import transaction, IntegrityError
|
from django.db import transaction, IntegrityError
|
||||||
@ -519,9 +520,11 @@ class BulkEditView(GetReturnURLMixin, BaseMultiObjectView):
|
|||||||
model_field = self.queryset.model._meta.get_field(name)
|
model_field = self.queryset.model._meta.get_field(name)
|
||||||
if isinstance(model_field, (ManyToManyField, ManyToManyRel)):
|
if isinstance(model_field, (ManyToManyField, ManyToManyRel)):
|
||||||
m2m_fields[name] = model_field
|
m2m_fields[name] = model_field
|
||||||
|
elif isinstance(model_field, GenericRel):
|
||||||
|
# Ignore generic relations (these may be used for other purposes in the form)
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
model_fields[name] = model_field
|
model_fields[name] = model_field
|
||||||
|
|
||||||
except FieldDoesNotExist:
|
except FieldDoesNotExist:
|
||||||
# This form field is used to modify a field rather than set its value directly
|
# This form field is used to modify a field rather than set its value directly
|
||||||
model_fields[name] = None
|
model_fields[name] = None
|
||||||
|
Loading…
Reference in New Issue
Block a user