Coverage for wireless/forms/bulk_edit.py: 100%

44 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from django import forms 

2from django.utils.translation import gettext_lazy as _ 

3 

4from dcim.choices import LinkStatusChoices 

5from dcim.forms.mixins import ScopedBulkEditForm 

6from ipam.models import VLAN 

7from netbox.choices import * 

8from netbox.forms import NestedGroupModelBulkEditForm, PrimaryModelBulkEditForm 

9from tenancy.models import Tenant 

10from utilities.forms import add_blank_choice 

11from utilities.forms.fields import ChoiceField, DynamicModelChoiceField 

12from utilities.forms.rendering import FieldSet 

13from wireless.choices import * 

14from wireless.constants import SSID_MAX_LENGTH 

15from wireless.models import * 

16 

17__all__ = ( 

18 'WirelessLANBulkEditForm', 

19 'WirelessLANGroupBulkEditForm', 

20 'WirelessLinkBulkEditForm', 

21) 

22 

23 

24class WirelessLANGroupBulkEditForm(NestedGroupModelBulkEditForm): 

25 parent = DynamicModelChoiceField( 

26 label=_('Parent'), 

27 queryset=WirelessLANGroup.objects.all(), 

28 required=False 

29 ) 

30 

31 model = WirelessLANGroup 

32 fieldsets = ( 

33 FieldSet('parent', 'description'), 

34 ) 

35 nullable_fields = ('parent', 'description', 'comments') 

36 

37 

38class WirelessLANBulkEditForm(ScopedBulkEditForm, PrimaryModelBulkEditForm): 

39 status = ChoiceField( 

40 label=_('Status'), 

41 choices=add_blank_choice(WirelessLANStatusChoices), 

42 required=False 

43 ) 

44 group = DynamicModelChoiceField( 

45 label=_('Group'), 

46 queryset=WirelessLANGroup.objects.all(), 

47 required=False 

48 ) 

49 vlan = DynamicModelChoiceField( 

50 queryset=VLAN.objects.all(), 

51 required=False, 

52 label=_('VLAN') 

53 ) 

54 ssid = forms.CharField( 

55 max_length=SSID_MAX_LENGTH, 

56 required=False, 

57 label=_('SSID') 

58 ) 

59 tenant = DynamicModelChoiceField( 

60 label=_('Tenant'), 

61 queryset=Tenant.objects.all(), 

62 required=False 

63 ) 

64 auth_type = ChoiceField( 

65 label=_('Authentication type'), 

66 choices=add_blank_choice(WirelessAuthTypeChoices), 

67 required=False 

68 ) 

69 auth_cipher = ChoiceField( 

70 label=_('Authentication cipher'), 

71 choices=add_blank_choice(WirelessAuthCipherChoices), 

72 required=False 

73 ) 

74 auth_psk = forms.CharField( 

75 required=False, 

76 label=_('Pre-shared key') 

77 ) 

78 

79 model = WirelessLAN 

80 fieldsets = ( 

81 FieldSet('group', 'ssid', 'status', 'vlan', 'tenant', 'description'), 

82 FieldSet('scope', name=_('Scope')), 

83 FieldSet('auth_type', 'auth_cipher', 'auth_psk', name=_('Authentication')), 

84 ) 

85 nullable_fields = ( 

86 'ssid', 'group', 'vlan', 'tenant', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'scope', 'comments', 

87 ) 

88 

89 

90class WirelessLinkBulkEditForm(PrimaryModelBulkEditForm): 

91 ssid = forms.CharField( 

92 max_length=SSID_MAX_LENGTH, 

93 required=False, 

94 label=_('SSID') 

95 ) 

96 status = ChoiceField( 

97 label=_('Status'), 

98 choices=add_blank_choice(LinkStatusChoices), 

99 required=False 

100 ) 

101 tenant = DynamicModelChoiceField( 

102 label=_('Tenant'), 

103 queryset=Tenant.objects.all(), 

104 required=False 

105 ) 

106 auth_type = ChoiceField( 

107 label=_('Authentication type'), 

108 choices=add_blank_choice(WirelessAuthTypeChoices), 

109 required=False 

110 ) 

111 auth_cipher = ChoiceField( 

112 label=_('Authentication cipher'), 

113 choices=add_blank_choice(WirelessAuthCipherChoices), 

114 required=False 

115 ) 

116 auth_psk = forms.CharField( 

117 required=False, 

118 label=_('Pre-shared key') 

119 ) 

120 distance = forms.DecimalField( 

121 label=_('Distance'), 

122 min_value=0, 

123 required=False 

124 ) 

125 distance_unit = ChoiceField( 

126 label=_('Distance unit'), 

127 choices=add_blank_choice(DistanceUnitChoices), 

128 required=False, 

129 initial='' 

130 ) 

131 

132 model = WirelessLink 

133 fieldsets = ( 

134 FieldSet('ssid', 'status', 'tenant', 'description'), 

135 FieldSet('auth_type', 'auth_cipher', 'auth_psk', name=_('Authentication')), 

136 FieldSet('distance', 'distance_unit', name=_('Attributes')), 

137 ) 

138 nullable_fields = ( 

139 'ssid', 'tenant', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'distance', 'comments', 

140 )