2
0

bulk_edit.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from django import forms
  2. from django.utils.translation import gettext_lazy as _
  3. from dcim.choices import LinkStatusChoices
  4. from dcim.forms.mixins import ScopedBulkEditForm
  5. from ipam.models import VLAN
  6. from netbox.choices import *
  7. from netbox.forms import NetBoxModelBulkEditForm
  8. from tenancy.models import Tenant
  9. from utilities.forms import add_blank_choice
  10. from utilities.forms.fields import CommentField, DynamicModelChoiceField
  11. from utilities.forms.rendering import FieldSet
  12. from wireless.choices import *
  13. from wireless.constants import SSID_MAX_LENGTH
  14. from wireless.models import *
  15. __all__ = (
  16. 'WirelessLANBulkEditForm',
  17. 'WirelessLANGroupBulkEditForm',
  18. 'WirelessLinkBulkEditForm',
  19. )
  20. class WirelessLANGroupBulkEditForm(NetBoxModelBulkEditForm):
  21. parent = DynamicModelChoiceField(
  22. label=_('Parent'),
  23. queryset=WirelessLANGroup.objects.all(),
  24. required=False
  25. )
  26. description = forms.CharField(
  27. label=_('Description'),
  28. max_length=200,
  29. required=False
  30. )
  31. comments = CommentField()
  32. model = WirelessLANGroup
  33. fieldsets = (
  34. FieldSet('parent', 'description'),
  35. )
  36. nullable_fields = ('parent', 'description', 'comments')
  37. class WirelessLANBulkEditForm(ScopedBulkEditForm, NetBoxModelBulkEditForm):
  38. status = forms.ChoiceField(
  39. label=_('Status'),
  40. choices=add_blank_choice(WirelessLANStatusChoices),
  41. required=False
  42. )
  43. group = DynamicModelChoiceField(
  44. label=_('Group'),
  45. queryset=WirelessLANGroup.objects.all(),
  46. required=False
  47. )
  48. vlan = DynamicModelChoiceField(
  49. queryset=VLAN.objects.all(),
  50. required=False,
  51. label=_('VLAN')
  52. )
  53. ssid = forms.CharField(
  54. max_length=SSID_MAX_LENGTH,
  55. required=False,
  56. label=_('SSID')
  57. )
  58. tenant = DynamicModelChoiceField(
  59. label=_('Tenant'),
  60. queryset=Tenant.objects.all(),
  61. required=False
  62. )
  63. auth_type = forms.ChoiceField(
  64. label=_('Authentication type'),
  65. choices=add_blank_choice(WirelessAuthTypeChoices),
  66. required=False
  67. )
  68. auth_cipher = forms.ChoiceField(
  69. label=_('Authentication cipher'),
  70. choices=add_blank_choice(WirelessAuthCipherChoices),
  71. required=False
  72. )
  73. auth_psk = forms.CharField(
  74. required=False,
  75. label=_('Pre-shared key')
  76. )
  77. description = forms.CharField(
  78. label=_('Description'),
  79. max_length=200,
  80. required=False
  81. )
  82. comments = CommentField()
  83. model = WirelessLAN
  84. fieldsets = (
  85. FieldSet('group', 'ssid', 'status', 'vlan', 'tenant', 'description'),
  86. FieldSet('scope_type', 'scope', name=_('Scope')),
  87. FieldSet('auth_type', 'auth_cipher', 'auth_psk', name=_('Authentication')),
  88. )
  89. nullable_fields = (
  90. 'ssid', 'group', 'vlan', 'tenant', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'scope', 'comments',
  91. )
  92. class WirelessLinkBulkEditForm(NetBoxModelBulkEditForm):
  93. ssid = forms.CharField(
  94. max_length=SSID_MAX_LENGTH,
  95. required=False,
  96. label=_('SSID')
  97. )
  98. status = forms.ChoiceField(
  99. label=_('Status'),
  100. choices=add_blank_choice(LinkStatusChoices),
  101. required=False
  102. )
  103. tenant = DynamicModelChoiceField(
  104. label=_('Tenant'),
  105. queryset=Tenant.objects.all(),
  106. required=False
  107. )
  108. auth_type = forms.ChoiceField(
  109. label=_('Authentication type'),
  110. choices=add_blank_choice(WirelessAuthTypeChoices),
  111. required=False
  112. )
  113. auth_cipher = forms.ChoiceField(
  114. label=_('Authentication cipher'),
  115. choices=add_blank_choice(WirelessAuthCipherChoices),
  116. required=False
  117. )
  118. auth_psk = forms.CharField(
  119. required=False,
  120. label=_('Pre-shared key')
  121. )
  122. distance = forms.DecimalField(
  123. label=_('Distance'),
  124. min_value=0,
  125. required=False
  126. )
  127. distance_unit = forms.ChoiceField(
  128. label=_('Distance unit'),
  129. choices=add_blank_choice(DistanceUnitChoices),
  130. required=False,
  131. initial=''
  132. )
  133. description = forms.CharField(
  134. label=_('Description'),
  135. max_length=200,
  136. required=False
  137. )
  138. comments = CommentField()
  139. model = WirelessLink
  140. fieldsets = (
  141. FieldSet('ssid', 'status', 'tenant', 'description'),
  142. FieldSet('auth_type', 'auth_cipher', 'auth_psk', name=_('Authentication')),
  143. FieldSet('distance', 'distance_unit', name=_('Attributes')),
  144. )
  145. nullable_fields = (
  146. 'ssid', 'tenant', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'distance', 'comments',
  147. )