mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Fixes #3840: Only show valid interface VLAN choices
This commit is contained in:
parent
823e1280d2
commit
9d846d7b87
@ -3,6 +3,7 @@
|
|||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
* [#3525](https://github.com/netbox-community/netbox/issues/3525) - Enable IP address filtering with multiple address terms
|
* [#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
|
## Bug Fixes
|
||||||
|
|
||||||
@ -42,7 +43,7 @@
|
|||||||
* [#3872](https://github.com/netbox-community/netbox/issues/3872) - Paginate related IPs on the IP address view
|
* [#3872](https://github.com/netbox-community/netbox/issues/3872) - Paginate related IPs on the IP address view
|
||||||
* [#3876](https://github.com/netbox-community/netbox/issues/3876) - Fix minimum/maximum value rendering for site ASN field
|
* [#3876](https://github.com/netbox-community/netbox/issues/3876) - Fix minimum/maximum value rendering for site ASN field
|
||||||
* [#3882](https://github.com/netbox-community/netbox/issues/3882) - Fix filtering of devices by rack group
|
* [#3882](https://github.com/netbox-community/netbox/issues/3882) - Fix filtering of devices by rack group
|
||||||
* [#3898](https://github.com/netbox-community/netbox/issues/3898) - Fix references to deleted cables without a label
|
* [#3898](https://github.com/netbox-community/netbox/issues/3898) - Fix references to deleted cables without a label
|
||||||
* [#3905](https://github.com/netbox-community/netbox/issues/3905) - Fix divide-by-zero on power feeds with low power values
|
* [#3905](https://github.com/netbox-community/netbox/issues/3905) - Fix divide-by-zero on power feeds with low power values
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -2238,7 +2238,10 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
|||||||
widget=APISelect(
|
widget=APISelect(
|
||||||
api_url="/api/ipam/vlans/",
|
api_url="/api/ipam/vlans/",
|
||||||
display_field='display_name',
|
display_field='display_name',
|
||||||
full=True
|
full=True,
|
||||||
|
additional_query_params={
|
||||||
|
'site_id': 'null',
|
||||||
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||||
@ -2247,7 +2250,10 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
|||||||
widget=APISelectMultiple(
|
widget=APISelectMultiple(
|
||||||
api_url="/api/ipam/vlans/",
|
api_url="/api/ipam/vlans/",
|
||||||
display_field='display_name',
|
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
|
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):
|
class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
||||||
name_pattern = ExpandableNameField(
|
name_pattern = ExpandableNameField(
|
||||||
@ -2340,7 +2350,10 @@ class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
|||||||
widget=APISelect(
|
widget=APISelect(
|
||||||
api_url="/api/ipam/vlans/",
|
api_url="/api/ipam/vlans/",
|
||||||
display_field='display_name',
|
display_field='display_name',
|
||||||
full=True
|
full=True,
|
||||||
|
additional_query_params={
|
||||||
|
'site_id': 'null',
|
||||||
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||||
@ -2349,7 +2362,10 @@ class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
|||||||
widget=APISelectMultiple(
|
widget=APISelectMultiple(
|
||||||
api_url="/api/ipam/vlans/",
|
api_url="/api/ipam/vlans/",
|
||||||
display_field='display_name',
|
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(
|
self.fields['lag'].queryset = Interface.objects.filter(
|
||||||
device__in=[self.parent, self.parent.get_vc_master()], type=IFACE_TYPE_LAG
|
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:
|
else:
|
||||||
self.fields['lag'].queryset = Interface.objects.none()
|
self.fields['lag'].queryset = Interface.objects.none()
|
||||||
|
|
||||||
@ -2420,7 +2440,10 @@ class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsFo
|
|||||||
widget=APISelect(
|
widget=APISelect(
|
||||||
api_url="/api/ipam/vlans/",
|
api_url="/api/ipam/vlans/",
|
||||||
display_field='display_name',
|
display_field='display_name',
|
||||||
full=True
|
full=True,
|
||||||
|
additional_query_params={
|
||||||
|
'site_id': 'null',
|
||||||
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||||
@ -2429,7 +2452,10 @@ class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsFo
|
|||||||
widget=APISelectMultiple(
|
widget=APISelectMultiple(
|
||||||
api_url="/api/ipam/vlans/",
|
api_url="/api/ipam/vlans/",
|
||||||
display_field='display_name',
|
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()],
|
device__in=[device, device.get_vc_master()],
|
||||||
type=IFACE_TYPE_LAG
|
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:
|
else:
|
||||||
self.fields['lag'].choices = []
|
self.fields['lag'].choices = []
|
||||||
|
|
||||||
|
@ -187,15 +187,18 @@ $(document).ready(function() {
|
|||||||
$.each(element.attributes, function(index, attr){
|
$.each(element.attributes, function(index, attr){
|
||||||
if (attr.name.includes("data-additional-query-param-")){
|
if (attr.name.includes("data-additional-query-param-")){
|
||||||
var param_name = attr.name.split("data-additional-query-param-")[1];
|
var param_name = attr.name.split("data-additional-query-param-")[1];
|
||||||
if (param_name in parameters) {
|
|
||||||
if (Array.isArray(parameters[param_name])) {
|
$.each($.parseJSON(attr.value), function(index, value) {
|
||||||
parameters[param_name].push(attr.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 {
|
} 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):
|
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 name: The name of the query param
|
||||||
:param value: The value 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):
|
def add_conditional_query_param(self, condition, value):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user