mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #3840: Only show valid interface VLAN choices
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
## Enhancements
|
||||
|
||||
* [#3525](https://github.com/netbox-community/netbox/issues/3525) - Enable IP address filtering with multiple address terms
|
||||
* [#3840](https://github.com/netbox-community/netbox/issues/3840) - Only show the valid list of interface VLAN choices
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
|
@ -2238,7 +2238,10 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
||||
widget=APISelect(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
full=True,
|
||||
additional_query_params={
|
||||
'site_id': 'null',
|
||||
},
|
||||
)
|
||||
)
|
||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||
@ -2247,7 +2250,10 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
||||
widget=APISelectMultiple(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
full=True,
|
||||
additional_query_params={
|
||||
'site_id': 'null',
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
@ -2289,6 +2295,10 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
||||
device__in=[self.instance.device, self.instance.device.get_vc_master()], type=IFACE_TYPE_LAG
|
||||
)
|
||||
|
||||
# Add current site to VLANs query params
|
||||
self.fields['untagged_vlan'].widget.add_additional_query_param('site_id', device.site.pk)
|
||||
self.fields['tagged_vlans'].widget.add_additional_query_param('site_id', device.site.pk)
|
||||
|
||||
|
||||
class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
||||
name_pattern = ExpandableNameField(
|
||||
@ -2340,7 +2350,10 @@ class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
||||
widget=APISelect(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
full=True,
|
||||
additional_query_params={
|
||||
'site_id': 'null',
|
||||
},
|
||||
)
|
||||
)
|
||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||
@ -2349,7 +2362,10 @@ class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
||||
widget=APISelectMultiple(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
full=True,
|
||||
additional_query_params={
|
||||
'site_id': 'null',
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
@ -2366,6 +2382,10 @@ class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
||||
self.fields['lag'].queryset = Interface.objects.filter(
|
||||
device__in=[self.parent, self.parent.get_vc_master()], type=IFACE_TYPE_LAG
|
||||
)
|
||||
|
||||
# Add current site to VLANs query params
|
||||
self.fields['untagged_vlan'].widget.add_additional_query_param('site_id', self.parent.site.pk)
|
||||
self.fields['tagged_vlans'].widget.add_additional_query_param('site_id', self.parent.site.pk)
|
||||
else:
|
||||
self.fields['lag'].queryset = Interface.objects.none()
|
||||
|
||||
@ -2420,7 +2440,10 @@ class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsFo
|
||||
widget=APISelect(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
full=True,
|
||||
additional_query_params={
|
||||
'site_id': 'null',
|
||||
},
|
||||
)
|
||||
)
|
||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||
@ -2429,7 +2452,10 @@ class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsFo
|
||||
widget=APISelectMultiple(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
full=True,
|
||||
additional_query_params={
|
||||
'site_id': 'null',
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
@ -2448,6 +2474,10 @@ class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsFo
|
||||
device__in=[device, device.get_vc_master()],
|
||||
type=IFACE_TYPE_LAG
|
||||
)
|
||||
|
||||
# Add current site to VLANs query params
|
||||
self.fields['untagged_vlan'].widget.add_additional_query_param('site_id', device.site.pk)
|
||||
self.fields['tagged_vlans'].widget.add_additional_query_param('site_id', device.site.pk)
|
||||
else:
|
||||
self.fields['lag'].choices = []
|
||||
|
||||
|
@ -187,15 +187,18 @@ $(document).ready(function() {
|
||||
$.each(element.attributes, function(index, attr){
|
||||
if (attr.name.includes("data-additional-query-param-")){
|
||||
var param_name = attr.name.split("data-additional-query-param-")[1];
|
||||
if (param_name in parameters) {
|
||||
if (Array.isArray(parameters[param_name])) {
|
||||
parameters[param_name].push(attr.value)
|
||||
|
||||
$.each($.parseJSON(attr.value), function(index, value) {
|
||||
if (param_name in parameters) {
|
||||
if (Array.isArray(parameters[param_name])) {
|
||||
parameters[param_name].push(value)
|
||||
} else {
|
||||
parameters[param_name] = [parameters[param_name], value]
|
||||
}
|
||||
} else {
|
||||
parameters[param_name] = [parameters[param_name], attr.value]
|
||||
parameters[param_name] = value;
|
||||
}
|
||||
} else {
|
||||
parameters[param_name] = attr.value;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -346,12 +346,17 @@ class APISelect(SelectWithDisabled):
|
||||
|
||||
def add_additional_query_param(self, name, value):
|
||||
"""
|
||||
Add details for an additional query param in the form of a data-* attribute.
|
||||
Add details for an additional query param in the form of a data-* JSON-encoded list attribute.
|
||||
|
||||
:param name: The name of the query param
|
||||
:param value: The value of the query param
|
||||
"""
|
||||
self.attrs['data-additional-query-param-{}'.format(name)] = value
|
||||
key = 'data-additional-query-param-{}'.format(name)
|
||||
|
||||
values = json.loads(self.attrs.get(key, '[]'))
|
||||
values.append(value)
|
||||
|
||||
self.attrs[key] = json.dumps(values)
|
||||
|
||||
def add_conditional_query_param(self, condition, value):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user