1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #6326: Enable filtering assigned VLANs by group in interface edit form

This commit is contained in:
jeremystretch
2021-08-23 12:49:32 -04:00
parent 0b0ab9277c
commit 8497965cf7
6 changed files with 35 additions and 6 deletions

View File

@ -13,6 +13,7 @@
### Bug Fixes ### Bug Fixes
* [#5968](https://github.com/netbox-community/netbox/issues/5968) - Model forms should save empty custom field values as null * [#5968](https://github.com/netbox-community/netbox/issues/5968) - Model forms should save empty custom field values as null
* [#6326](https://github.com/netbox-community/netbox/issues/6326) - Enable filtering assigned VLANs by group in interface edit form
* [#6686](https://github.com/netbox-community/netbox/issues/6686) - Force assignment of null custom field values to objects * [#6686](https://github.com/netbox-community/netbox/issues/6686) - Force assignment of null custom field values to objects
* [#6776](https://github.com/netbox-community/netbox/issues/6776) - Fix erroneous webhook dispatch on failure to save objects * [#6776](https://github.com/netbox-community/netbox/issues/6776) - Fix erroneous webhook dispatch on failure to save objects
* [#6974](https://github.com/netbox-community/netbox/issues/6974) - Show contextual label for IP address role * [#6974](https://github.com/netbox-community/netbox/issues/6974) - Show contextual label for IP address role

View File

@ -18,7 +18,7 @@ from extras.forms import (
) )
from extras.models import Tag from extras.models import Tag
from ipam.constants import BGP_ASN_MAX, BGP_ASN_MIN from ipam.constants import BGP_ASN_MAX, BGP_ASN_MIN
from ipam.models import IPAddress, VLAN from ipam.models import IPAddress, VLAN, VLANGroup
from tenancy.forms import TenancyFilterForm, TenancyForm from tenancy.forms import TenancyFilterForm, TenancyForm
from tenancy.models import Tenant from tenancy.models import Tenant
from utilities.forms import ( from utilities.forms import (
@ -3109,15 +3109,26 @@ class InterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm):
'type': 'lag', 'type': 'lag',
} }
) )
vlan_group = DynamicModelChoiceField(
queryset=VLANGroup.objects.all(),
required=False,
label='VLAN group'
)
untagged_vlan = DynamicModelChoiceField( untagged_vlan = DynamicModelChoiceField(
queryset=VLAN.objects.all(), queryset=VLAN.objects.all(),
required=False, required=False,
label='Untagged VLAN' label='Untagged VLAN',
query_params={
'group_id': '$vlan_group',
}
) )
tagged_vlans = DynamicModelMultipleChoiceField( tagged_vlans = DynamicModelMultipleChoiceField(
queryset=VLAN.objects.all(), queryset=VLAN.objects.all(),
required=False, required=False,
label='Tagged VLANs' label='Tagged VLANs',
query_params={
'group_id': '$vlan_group',
}
) )
tags = DynamicModelMultipleChoiceField( tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(), queryset=Tag.objects.all(),

View File

@ -337,22 +337,26 @@ $(document).ready(function() {
$('select#id_untagged_vlan').trigger('change'); $('select#id_untagged_vlan').trigger('change');
$('select#id_tagged_vlans').val([]); $('select#id_tagged_vlans').val([]);
$('select#id_tagged_vlans').trigger('change'); $('select#id_tagged_vlans').trigger('change');
$('select#id_vlan_group').parent().parent().hide();
$('select#id_untagged_vlan').parent().parent().hide(); $('select#id_untagged_vlan').parent().parent().hide();
$('select#id_tagged_vlans').parent().parent().hide(); $('select#id_tagged_vlans').parent().parent().hide();
} }
else if ($(this).val() == 'access') { else if ($(this).val() == 'access') {
$('select#id_tagged_vlans').val([]); $('select#id_tagged_vlans').val([]);
$('select#id_tagged_vlans').trigger('change'); $('select#id_tagged_vlans').trigger('change');
$('select#id_vlan_group').parent().parent().show();
$('select#id_untagged_vlan').parent().parent().show(); $('select#id_untagged_vlan').parent().parent().show();
$('select#id_tagged_vlans').parent().parent().hide(); $('select#id_tagged_vlans').parent().parent().hide();
} }
else if ($(this).val() == 'tagged') { else if ($(this).val() == 'tagged') {
$('select#id_vlan_group').parent().parent().show();
$('select#id_untagged_vlan').parent().parent().show(); $('select#id_untagged_vlan').parent().parent().show();
$('select#id_tagged_vlans').parent().parent().show(); $('select#id_tagged_vlans').parent().parent().show();
} }
else if ($(this).val() == 'tagged-all') { else if ($(this).val() == 'tagged-all') {
$('select#id_tagged_vlans').val([]); $('select#id_tagged_vlans').val([]);
$('select#id_tagged_vlans').trigger('change'); $('select#id_tagged_vlans').trigger('change');
$('select#id_vlan_group').parent().parent().show();
$('select#id_untagged_vlan').parent().parent().show(); $('select#id_untagged_vlan').parent().parent().show();
$('select#id_tagged_vlans').parent().parent().hide(); $('select#id_tagged_vlans').parent().parent().hide();
} }

View File

@ -33,6 +33,7 @@
<div class="panel-heading"><strong>802.1Q Switching</strong></div> <div class="panel-heading"><strong>802.1Q Switching</strong></div>
<div class="panel-body"> <div class="panel-body">
{% render_field form.mode %} {% render_field form.mode %}
{% render_field form.vlan_group %}
{% render_field form.untagged_vlan %} {% render_field form.untagged_vlan %}
{% render_field form.tagged_vlans %} {% render_field form.tagged_vlans %}
</div> </div>

View File

@ -28,6 +28,7 @@
<div class="panel-heading"><strong>802.1Q Switching</strong></div> <div class="panel-heading"><strong>802.1Q Switching</strong></div>
<div class="panel-body"> <div class="panel-body">
{% render_field form.mode %} {% render_field form.mode %}
{% render_field form.vlan_group %}
{% render_field form.untagged_vlan %} {% render_field form.untagged_vlan %}
{% render_field form.tagged_vlans %} {% render_field form.tagged_vlans %}
</div> </div>

View File

@ -12,7 +12,7 @@ from extras.forms import (
CustomFieldFilterForm, CustomFieldFilterForm,
) )
from extras.models import Tag from extras.models import Tag
from ipam.models import IPAddress, VLAN from ipam.models import IPAddress, VLAN, VLANGroup
from tenancy.forms import TenancyFilterForm, TenancyForm from tenancy.forms import TenancyFilterForm, TenancyForm
from tenancy.models import Tenant from tenancy.models import Tenant
from utilities.forms import ( from utilities.forms import (
@ -616,15 +616,26 @@ class VMInterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm)
required=False, required=False,
label='Parent interface' label='Parent interface'
) )
vlan_group = DynamicModelChoiceField(
queryset=VLANGroup.objects.all(),
required=False,
label='VLAN group'
)
untagged_vlan = DynamicModelChoiceField( untagged_vlan = DynamicModelChoiceField(
queryset=VLAN.objects.all(), queryset=VLAN.objects.all(),
required=False, required=False,
label='Untagged VLAN' label='Untagged VLAN',
query_params={
'group_id': '$vlan_group',
}
) )
tagged_vlans = DynamicModelMultipleChoiceField( tagged_vlans = DynamicModelMultipleChoiceField(
queryset=VLAN.objects.all(), queryset=VLAN.objects.all(),
required=False, required=False,
label='Tagged VLANs' label='Tagged VLANs',
query_params={
'group_id': '$vlan_group',
}
) )
tags = DynamicModelMultipleChoiceField( tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(), queryset=Tag.objects.all(),