mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 21:02:23 -06:00
Use FieldSet instances for all forms
This commit is contained in:
@@ -5,6 +5,7 @@ from netbox.forms import NetBoxModelBulkEditForm
|
||||
from tenancy.models import Tenant
|
||||
from utilities.forms import add_blank_choice
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from vpn.choices import *
|
||||
from vpn.models import *
|
||||
|
||||
@@ -72,9 +73,9 @@ class TunnelBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = Tunnel
|
||||
fieldsets = (
|
||||
(_('Tunnel'), ('status', 'group', 'encapsulation', 'tunnel_id', 'description')),
|
||||
(_('Security'), ('ipsec_profile',)),
|
||||
(_('Tenancy'), ('tenant',)),
|
||||
FieldSet('status', 'group', 'encapsulation', 'tunnel_id', 'description', name=_('Tunnel')),
|
||||
FieldSet('ipsec_profile', name=_('Security')),
|
||||
FieldSet('tenant', name=_('Tenancy')),
|
||||
)
|
||||
nullable_fields = (
|
||||
'group', 'ipsec_profile', 'tunnel_id', 'tenant', 'description', 'comments',
|
||||
@@ -125,10 +126,10 @@ class IKEProposalBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = IKEProposal
|
||||
fieldsets = (
|
||||
(None, (
|
||||
FieldSet(
|
||||
'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', 'sa_lifetime',
|
||||
'description',
|
||||
)),
|
||||
),
|
||||
)
|
||||
nullable_fields = (
|
||||
'sa_lifetime', 'description', 'comments',
|
||||
@@ -159,9 +160,7 @@ class IKEPolicyBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = IKEPolicy
|
||||
fieldsets = (
|
||||
(None, (
|
||||
'version', 'mode', 'preshared_key', 'description',
|
||||
)),
|
||||
FieldSet('version', 'mode', 'preshared_key', 'description'),
|
||||
)
|
||||
nullable_fields = (
|
||||
'mode', 'preshared_key', 'description', 'comments',
|
||||
@@ -196,10 +195,10 @@ class IPSecProposalBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = IPSecProposal
|
||||
fieldsets = (
|
||||
(None, (
|
||||
FieldSet(
|
||||
'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', 'sa_lifetime_data',
|
||||
'description',
|
||||
)),
|
||||
),
|
||||
)
|
||||
nullable_fields = (
|
||||
'sa_lifetime_seconds', 'sa_lifetime_data', 'description', 'comments',
|
||||
@@ -221,7 +220,7 @@ class IPSecPolicyBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = IPSecPolicy
|
||||
fieldsets = (
|
||||
(None, ('pfs_group', 'description',)),
|
||||
FieldSet('pfs_group', 'description'),
|
||||
)
|
||||
nullable_fields = (
|
||||
'pfs_group', 'description', 'comments',
|
||||
@@ -253,9 +252,7 @@ class IPSecProfileBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = IPSecProfile
|
||||
fieldsets = (
|
||||
(_('Profile'), (
|
||||
'mode', 'ike_policy', 'ipsec_policy', 'description',
|
||||
)),
|
||||
FieldSet('mode', 'ike_policy', 'ipsec_policy', 'description', name=_('Profile')),
|
||||
)
|
||||
nullable_fields = (
|
||||
'description', 'comments',
|
||||
@@ -282,7 +279,7 @@ class L2VPNBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = L2VPN
|
||||
fieldsets = (
|
||||
(None, ('type', 'tenant', 'description')),
|
||||
FieldSet('type', 'tenant', 'description'),
|
||||
)
|
||||
nullable_fields = ('tenant', 'description', 'comments')
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from tenancy.forms import TenancyFilterForm
|
||||
from utilities.forms.fields import (
|
||||
ContentTypeMultipleChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, TagFilterField,
|
||||
)
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.utils import add_blank_choice
|
||||
from virtualization.models import VirtualMachine
|
||||
from vpn.choices import *
|
||||
@@ -37,10 +38,10 @@ class TunnelGroupFilterForm(NetBoxModelFilterSetForm):
|
||||
class TunnelFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
model = Tunnel
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Tunnel'), ('status', 'encapsulation', 'tunnel_id')),
|
||||
(_('Security'), ('ipsec_profile_id',)),
|
||||
(_('Tenancy'), ('tenant_group_id', 'tenant_id')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('status', 'encapsulation', 'tunnel_id', name=_('Tunnel')),
|
||||
FieldSet('ipsec_profile_id', name=_('Security')),
|
||||
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenancy')),
|
||||
)
|
||||
status = forms.MultipleChoiceField(
|
||||
label=_('Status'),
|
||||
@@ -72,8 +73,8 @@ class TunnelFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
class TunnelTerminationFilterForm(NetBoxModelFilterSetForm):
|
||||
model = TunnelTermination
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Termination'), ('tunnel_id', 'role')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('tunnel_id', 'role', name=_('Termination')),
|
||||
)
|
||||
tunnel_id = DynamicModelMultipleChoiceField(
|
||||
queryset=Tunnel.objects.all(),
|
||||
@@ -91,8 +92,10 @@ class TunnelTerminationFilterForm(NetBoxModelFilterSetForm):
|
||||
class IKEProposalFilterForm(NetBoxModelFilterSetForm):
|
||||
model = IKEProposal
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Parameters'), ('authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet(
|
||||
'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', name=_('Parameters')
|
||||
),
|
||||
)
|
||||
authentication_method = forms.MultipleChoiceField(
|
||||
label=_('Authentication method'),
|
||||
@@ -120,8 +123,8 @@ class IKEProposalFilterForm(NetBoxModelFilterSetForm):
|
||||
class IKEPolicyFilterForm(NetBoxModelFilterSetForm):
|
||||
model = IKEPolicy
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Parameters'), ('version', 'mode', 'proposal_id')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('version', 'mode', 'proposal_id', name=_('Parameters')),
|
||||
)
|
||||
version = forms.MultipleChoiceField(
|
||||
label=_('IKE version'),
|
||||
@@ -144,8 +147,8 @@ class IKEPolicyFilterForm(NetBoxModelFilterSetForm):
|
||||
class IPSecProposalFilterForm(NetBoxModelFilterSetForm):
|
||||
model = IPSecProposal
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Parameters'), ('encryption_algorithm', 'authentication_algorithm')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('encryption_algorithm', 'authentication_algorithm', name=_('Parameters')),
|
||||
)
|
||||
encryption_algorithm = forms.MultipleChoiceField(
|
||||
label=_('Encryption algorithm'),
|
||||
@@ -163,8 +166,8 @@ class IPSecProposalFilterForm(NetBoxModelFilterSetForm):
|
||||
class IPSecPolicyFilterForm(NetBoxModelFilterSetForm):
|
||||
model = IPSecPolicy
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Parameters'), ('proposal_id', 'pfs_group')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('proposal_id', 'pfs_group', name=_('Parameters')),
|
||||
)
|
||||
proposal_id = DynamicModelMultipleChoiceField(
|
||||
queryset=IKEProposal.objects.all(),
|
||||
@@ -182,8 +185,8 @@ class IPSecPolicyFilterForm(NetBoxModelFilterSetForm):
|
||||
class IPSecProfileFilterForm(NetBoxModelFilterSetForm):
|
||||
model = IPSecProfile
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Profile'), ('mode', 'ike_policy_id', 'ipsec_policy_id')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('mode', 'ike_policy_id', 'ipsec_policy_id', name=_('Profile')),
|
||||
)
|
||||
mode = forms.MultipleChoiceField(
|
||||
label=_('Mode'),
|
||||
@@ -206,9 +209,9 @@ class IPSecProfileFilterForm(NetBoxModelFilterSetForm):
|
||||
class L2VPNFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
model = L2VPN
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Attributes'), ('type', 'import_target_id', 'export_target_id')),
|
||||
(_('Tenant'), ('tenant_group_id', 'tenant_id')),
|
||||
FieldSet('q', 'filter_id', 'tag'),
|
||||
FieldSet('type', 'import_target_id', 'export_target_id', name=_('Attributes')),
|
||||
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
|
||||
)
|
||||
type = forms.ChoiceField(
|
||||
label=_('Type'),
|
||||
@@ -231,10 +234,11 @@ class L2VPNFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
class L2VPNTerminationFilterForm(NetBoxModelFilterSetForm):
|
||||
model = L2VPNTermination
|
||||
fieldsets = (
|
||||
(None, ('filter_id', 'l2vpn_id',)),
|
||||
(_('Assigned Object'), (
|
||||
FieldSet('filter_id', 'l2vpn_id',),
|
||||
FieldSet(
|
||||
'assigned_object_type_id', 'region_id', 'site_id', 'device_id', 'virtual_machine_id', 'vlan_id',
|
||||
)),
|
||||
name=_('Assigned Object')
|
||||
),
|
||||
)
|
||||
l2vpn_id = DynamicModelChoiceField(
|
||||
queryset=L2VPN.objects.all(),
|
||||
|
||||
@@ -7,7 +7,7 @@ from ipam.models import IPAddress, RouteTarget, VLAN
|
||||
from netbox.forms import NetBoxModelForm
|
||||
from tenancy.forms import TenancyForm
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField
|
||||
from utilities.forms.rendering import TabbedGroups
|
||||
from utilities.forms.rendering import FieldSet, TabbedGroups
|
||||
from utilities.forms.utils import add_blank_choice, get_field_value
|
||||
from utilities.forms.widgets import HTMXSelect
|
||||
from virtualization.models import VirtualMachine, VMInterface
|
||||
@@ -33,7 +33,7 @@ class TunnelGroupForm(NetBoxModelForm):
|
||||
slug = SlugField()
|
||||
|
||||
fieldsets = (
|
||||
(_('Tunnel Group'), ('name', 'slug', 'description', 'tags')),
|
||||
FieldSet('name', 'slug', 'description', 'tags', name=_('Tunnel Group')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -57,9 +57,9 @@ class TunnelForm(TenancyForm, NetBoxModelForm):
|
||||
comments = CommentField()
|
||||
|
||||
fieldsets = (
|
||||
(_('Tunnel'), ('name', 'status', 'group', 'encapsulation', 'description', 'tunnel_id', 'tags')),
|
||||
(_('Security'), ('ipsec_profile',)),
|
||||
(_('Tenancy'), ('tenant_group', 'tenant')),
|
||||
FieldSet('name', 'status', 'group', 'encapsulation', 'description', 'tunnel_id', 'tags', name=_('Tunnel')),
|
||||
FieldSet('ipsec_profile', name=_('Security')),
|
||||
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -142,17 +142,15 @@ class TunnelCreateForm(TunnelForm):
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
(_('Tunnel'), ('name', 'status', 'group', 'encapsulation', 'description', 'tunnel_id', 'tags')),
|
||||
(_('Security'), ('ipsec_profile',)),
|
||||
(_('Tenancy'), ('tenant_group', 'tenant')),
|
||||
(_('First Termination'), (
|
||||
FieldSet('name', 'status', 'group', 'encapsulation', 'description', 'tunnel_id', 'tags', name=_('Tunnel')),
|
||||
FieldSet('ipsec_profile', name=_('Security')),
|
||||
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
||||
FieldSet(
|
||||
'termination1_role', 'termination1_type', 'termination1_parent', 'termination1_termination',
|
||||
'termination1_outside_ip',
|
||||
)),
|
||||
(_('Second Termination'), (
|
||||
'termination1_outside_ip', name=_('First Termination')),
|
||||
FieldSet(
|
||||
'termination2_role', 'termination2_type', 'termination2_parent', 'termination2_termination',
|
||||
'termination2_outside_ip',
|
||||
)),
|
||||
'termination2_outside_ip', name=_('Second Termination')),
|
||||
)
|
||||
|
||||
def __init__(self, *args, initial=None, **kwargs):
|
||||
@@ -254,7 +252,7 @@ class TunnelTerminationForm(NetBoxModelForm):
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
(None, ('tunnel', 'role', 'type', 'parent', 'termination', 'outside_ip', 'tags')),
|
||||
FieldSet('tunnel', 'role', 'type', 'parent', 'termination', 'outside_ip', 'tags'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -297,10 +295,11 @@ class TunnelTerminationForm(NetBoxModelForm):
|
||||
class IKEProposalForm(NetBoxModelForm):
|
||||
|
||||
fieldsets = (
|
||||
(_('Proposal'), ('name', 'description', 'tags')),
|
||||
(_('Parameters'), (
|
||||
FieldSet('name', 'description', 'tags', name=_('Proposal')),
|
||||
FieldSet(
|
||||
'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', 'sa_lifetime',
|
||||
)),
|
||||
name=_('Parameters')
|
||||
),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -318,8 +317,8 @@ class IKEPolicyForm(NetBoxModelForm):
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
(_('Policy'), ('name', 'description', 'tags')),
|
||||
(_('Parameters'), ('version', 'mode', 'proposals', 'preshared_key')),
|
||||
FieldSet('name', 'description', 'tags', name=_('Policy')),
|
||||
FieldSet('version', 'mode', 'proposals', 'preshared_key', name=_('Parameters')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -332,10 +331,11 @@ class IKEPolicyForm(NetBoxModelForm):
|
||||
class IPSecProposalForm(NetBoxModelForm):
|
||||
|
||||
fieldsets = (
|
||||
(_('Proposal'), ('name', 'description', 'tags')),
|
||||
(_('Parameters'), (
|
||||
FieldSet('name', 'description', 'tags', name=_('Proposal')),
|
||||
FieldSet(
|
||||
'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', 'sa_lifetime_data',
|
||||
)),
|
||||
name=_('Parameters')
|
||||
),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -353,8 +353,8 @@ class IPSecPolicyForm(NetBoxModelForm):
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
(_('Policy'), ('name', 'description', 'tags')),
|
||||
(_('Parameters'), ('proposals', 'pfs_group')),
|
||||
FieldSet('name', 'description', 'tags', name=_('Policy')),
|
||||
FieldSet('proposals', 'pfs_group', name=_('Parameters')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -376,8 +376,8 @@ class IPSecProfileForm(NetBoxModelForm):
|
||||
comments = CommentField()
|
||||
|
||||
fieldsets = (
|
||||
(_('Profile'), ('name', 'description', 'tags')),
|
||||
(_('Parameters'), ('mode', 'ike_policy', 'ipsec_policy')),
|
||||
FieldSet('name', 'description', 'tags', name=_('Profile')),
|
||||
FieldSet('mode', 'ike_policy', 'ipsec_policy', name=_('Parameters')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -406,9 +406,9 @@ class L2VPNForm(TenancyForm, NetBoxModelForm):
|
||||
comments = CommentField()
|
||||
|
||||
fieldsets = (
|
||||
(_('L2VPN'), ('name', 'slug', 'type', 'identifier', 'description', 'tags')),
|
||||
(_('Route Targets'), ('import_targets', 'export_targets')),
|
||||
(_('Tenancy'), ('tenant_group', 'tenant')),
|
||||
FieldSet('name', 'slug', 'type', 'identifier', 'description', 'tags', name=_('L2VPN')),
|
||||
FieldSet('import_targets', 'export_targets', name=_('Route Targets')),
|
||||
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -446,15 +446,15 @@ class L2VPNTerminationForm(NetBoxModelForm):
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
(None, (
|
||||
FieldSet(
|
||||
'l2vpn',
|
||||
TabbedGroups(
|
||||
(_('VLAN'), 'vlan'),
|
||||
(_('Device'), 'interface'),
|
||||
(_('Virtual Machine'), 'vminterface'),
|
||||
FieldSet('vlan', name=_('VLAN')),
|
||||
FieldSet('interface', name=_('Device')),
|
||||
FieldSet('vminterface', name=_('Virtual Machine')),
|
||||
),
|
||||
'tags',
|
||||
)),
|
||||
),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user