Closes: #15239 - Allow adding/removing tagged VLANs in bulk editing of Interfaces (#17524)

* Allow adding/removing tagged VLANs in bulk editing of Interfaces

* Move vlan/interface-specific field operations to an overrideable method

* Ensure interfaces are MODE_TAGGED before adding/removing tagged vlans

* Add docstring for generic extra_object_field_operations

* Move tagging ops into post_save_operations and use a TabbedGroup in the form
This commit is contained in:
bctiemann
2024-11-07 09:14:33 -05:00
committed by GitHub
parent 6035ad139a
commit f873735dd4
3 changed files with 68 additions and 23 deletions

View File

@@ -35,7 +35,7 @@ from virtualization.forms import VirtualMachineFilterForm
from virtualization.models import VirtualMachine
from virtualization.tables import VirtualMachineTable
from . import filtersets, forms, tables
from .choices import DeviceFaceChoices
from .choices import DeviceFaceChoices, InterfaceModeChoices
from .models import *
CABLE_TERMINATION_TYPES = {
@@ -2616,6 +2616,16 @@ class InterfaceBulkEditView(generic.BulkEditView):
table = tables.InterfaceTable
form = forms.InterfaceBulkEditForm
def post_save_operations(self, form, obj):
super().post_save_operations(form, obj)
# Add/remove tagged VLANs
if obj.mode == InterfaceModeChoices.MODE_TAGGED:
if form.cleaned_data.get('add_tagged_vlans', None):
obj.tagged_vlans.add(*form.cleaned_data['add_tagged_vlans'])
if form.cleaned_data.get('remove_tagged_vlans', None):
obj.tagged_vlans.remove(*form.cleaned_data['remove_tagged_vlans'])
class InterfaceBulkRenameView(generic.BulkRenameView):
queryset = Interface.objects.all()