From 939065bfef8c5e65753f04cdc6081b37f912262e Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Mon, 16 Sep 2024 15:15:51 -0500 Subject: [PATCH] Update bulk_edit forms --- netbox_routing/forms/bulk_edit/__init__.py | 5 ++- netbox_routing/forms/bulk_edit/ospf.py | 23 +++++++++--- netbox_routing/forms/bulk_edit/static.py | 41 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 netbox_routing/forms/bulk_edit/static.py diff --git a/netbox_routing/forms/bulk_edit/__init__.py b/netbox_routing/forms/bulk_edit/__init__.py index ac9fa62..57c16b9 100644 --- a/netbox_routing/forms/bulk_edit/__init__.py +++ b/netbox_routing/forms/bulk_edit/__init__.py @@ -1,9 +1,12 @@ +from .static import * from .objects import * from .ospf import OSPFInterfaceBulkEditForm __all__ = ( - + # Staticroute + 'StaticRouteBulkEditForm', + # OSPF 'OSPFInterfaceBulkEditForm', diff --git a/netbox_routing/forms/bulk_edit/ospf.py b/netbox_routing/forms/bulk_edit/ospf.py index 0aac495..3d9133b 100644 --- a/netbox_routing/forms/bulk_edit/ospf.py +++ b/netbox_routing/forms/bulk_edit/ospf.py @@ -1,32 +1,45 @@ +from django import forms from django.utils.translation import gettext as _ from netbox.forms import NetBoxModelBulkEditForm -from netbox_routing.models import OSPFArea, OSPFInstance, OSPFInterface +from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES, add_blank_choice from utilities.forms.fields import DynamicModelChoiceField +from netbox_routing import choices +from netbox_routing.models import OSPFArea, OSPFInstance, OSPFInterface __all__ = ( 'OSPFInterfaceBulkEditForm', ) +from utilities.forms.rendering import FieldSet + class OSPFInterfaceBulkEditForm(NetBoxModelBulkEditForm): instance = DynamicModelChoiceField( queryset=OSPFInstance.objects.all(), - label=_('Route Map'), + label=_('OSPF Instance'), required=False, selector=True ) area = DynamicModelChoiceField( queryset=OSPFArea.objects.all(), - label=_('Route Map'), + label=_('OSPF Area'), required=False, selector=True ) + priority = forms.IntegerField(label=_('Priority'), required=False) + bfd = forms.ChoiceField(label=_('BFD'), choices=BOOLEAN_WITH_BLANK_CHOICES, required=False) + authentication = forms.ChoiceField( + label=_('Authentication'), + choices=add_blank_choice(choices.AuthenticationChoices), + required=False + ) + passphrase = forms.CharField(label=_('Passphrase'), required=False) model = OSPFInterface fieldsets = ( - ('OSPF', ('instance', 'area')), - ('Attributes', ('priority', 'bfd', 'authentication', 'passphrase')), + FieldSet('instance', 'area', name='OSPF'), + FieldSet('priority', 'bfd', 'authentication', 'passphrase', name='Attributes'), ) nullable_fields = () diff --git a/netbox_routing/forms/bulk_edit/static.py b/netbox_routing/forms/bulk_edit/static.py new file mode 100644 index 0000000..bdf514a --- /dev/null +++ b/netbox_routing/forms/bulk_edit/static.py @@ -0,0 +1,41 @@ +from django import forms +from django.utils.translation import gettext as _ + +from dcim.models import Device +from ipam.models import VRF +from netbox.forms import NetBoxModelBulkEditForm +from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES +from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField +from utilities.forms.rendering import FieldSet + +from netbox_routing.models import StaticRoute + + +__all__ = ( + 'StaticRouteBulkEditForm', +) + + +class StaticRouteBulkEditForm(NetBoxModelBulkEditForm): + devices = DynamicModelMultipleChoiceField( + label='Device', + queryset=Device.objects.all(), + required=False, + selector=True, + ) + vrf = DynamicModelChoiceField( + label='VRF', + queryset=VRF.objects.all(), + required=False, + selector=True, + ) + metric = forms.IntegerField(label=_('Metric'), required=False) + permanent = forms.ChoiceField(label=_('Permanent'), choices=BOOLEAN_WITH_BLANK_CHOICES, required=False) + + model = StaticRoute + fieldsets = ( + FieldSet('devices', 'vrf', 'prefix', 'next_hop', name='Route'), + FieldSet('metric', 'permanent', name='Attributes'), + FieldSet('description', 'comments') + ) + nullable_fields = ('devices', 'vrf', 'metric', 'permanent', 'description', 'comments')