2023-04-24 11:13:28 -05:00
|
|
|
from django.forms import PasswordInput
|
2022-11-03 11:58:26 -07:00
|
|
|
from django.utils.translation import gettext as _
|
2023-04-14 10:33:53 -04:00
|
|
|
|
|
|
|
from dcim.models import Device, Interface, Location, Site
|
|
|
|
from ipam.models import VLAN
|
2022-01-28 15:48:15 -05:00
|
|
|
from netbox.forms import NetBoxModelForm
|
2022-06-27 11:30:52 -04:00
|
|
|
from tenancy.forms import TenancyForm
|
2023-04-14 10:33:53 -04:00
|
|
|
from utilities.forms.fields import CommentField, DynamicModelChoiceField, SlugField
|
2021-10-13 09:46:17 -04:00
|
|
|
from wireless.models import *
|
2021-10-12 12:27:12 -04:00
|
|
|
|
|
|
|
__all__ = (
|
2021-10-12 17:02:53 -04:00
|
|
|
'WirelessLANForm',
|
2021-10-13 16:40:12 -04:00
|
|
|
'WirelessLANGroupForm',
|
2021-10-13 09:46:17 -04:00
|
|
|
'WirelessLinkForm',
|
2021-10-12 12:27:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-28 15:48:15 -05:00
|
|
|
class WirelessLANGroupForm(NetBoxModelForm):
|
2021-10-13 16:40:12 -04:00
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=WirelessLANGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
slug = SlugField()
|
|
|
|
|
2022-10-19 05:35:23 -07:00
|
|
|
fieldsets = (
|
|
|
|
('Wireless LAN Group', (
|
|
|
|
'parent', 'name', 'slug', 'description', 'tags',
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
|
2021-10-13 16:40:12 -04:00
|
|
|
class Meta:
|
|
|
|
model = WirelessLANGroup
|
|
|
|
fields = [
|
2021-10-21 13:19:52 -04:00
|
|
|
'parent', 'name', 'slug', 'description', 'tags',
|
2021-10-13 16:40:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-06-27 11:30:52 -04:00
|
|
|
class WirelessLANForm(TenancyForm, NetBoxModelForm):
|
2021-10-13 16:40:12 -04:00
|
|
|
group = DynamicModelChoiceField(
|
|
|
|
queryset=WirelessLANGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2021-10-12 12:27:12 -04:00
|
|
|
vlan = DynamicModelChoiceField(
|
|
|
|
queryset=VLAN.objects.all(),
|
2021-10-20 10:58:15 -04:00
|
|
|
required=False,
|
2023-03-13 12:44:26 -04:00
|
|
|
selector=True,
|
|
|
|
label=_('VLAN')
|
2021-10-12 12:27:12 -04:00
|
|
|
)
|
2022-11-04 08:28:09 -04:00
|
|
|
comments = CommentField()
|
2021-10-12 12:27:12 -04:00
|
|
|
|
2022-01-31 15:52:36 -05:00
|
|
|
fieldsets = (
|
2023-03-13 12:44:26 -04:00
|
|
|
('Wireless LAN', ('ssid', 'group', 'vlan', 'status', 'description', 'tags')),
|
2022-06-27 11:30:52 -04:00
|
|
|
('Tenancy', ('tenant_group', 'tenant')),
|
2022-01-31 15:52:36 -05:00
|
|
|
('Authentication', ('auth_type', 'auth_cipher', 'auth_psk')),
|
|
|
|
)
|
|
|
|
|
2021-10-12 12:27:12 -04:00
|
|
|
class Meta:
|
2021-10-12 17:02:53 -04:00
|
|
|
model = WirelessLAN
|
2021-10-12 12:27:12 -04:00
|
|
|
fields = [
|
2023-03-13 12:44:26 -04:00
|
|
|
'ssid', 'group', 'status', 'vlan', 'tenant_group', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk',
|
|
|
|
'description', 'comments', 'tags',
|
2021-10-12 12:27:12 -04:00
|
|
|
]
|
2021-10-20 10:58:15 -04:00
|
|
|
widgets = {
|
2023-04-24 11:13:28 -05:00
|
|
|
'auth_psk': PasswordInput(
|
|
|
|
render_value=True,
|
|
|
|
attrs={'data-toggle': 'password'}
|
|
|
|
),
|
2021-10-20 10:58:15 -04:00
|
|
|
}
|
2021-10-13 09:46:17 -04:00
|
|
|
|
|
|
|
|
2022-06-27 11:30:52 -04:00
|
|
|
class WirelessLinkForm(TenancyForm, NetBoxModelForm):
|
2021-10-21 14:11:11 -04:00
|
|
|
site_a = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Site'),
|
2021-10-21 14:11:11 -04:00
|
|
|
initial_params={
|
|
|
|
'devices': '$device_a',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
location_a = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2022-04-18 09:02:03 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site_a',
|
|
|
|
},
|
2021-10-21 14:11:11 -04:00
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Location'),
|
2021-10-21 14:11:11 -04:00
|
|
|
initial_params={
|
|
|
|
'devices': '$device_a',
|
|
|
|
}
|
|
|
|
)
|
2021-10-14 10:02:05 -04:00
|
|
|
device_a = DynamicModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
2021-10-21 14:11:11 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site_a',
|
|
|
|
'location_id': '$location_a',
|
|
|
|
},
|
2021-10-20 13:34:39 -04:00
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Device'),
|
2021-10-15 11:35:10 -04:00
|
|
|
initial_params={
|
|
|
|
'interfaces': '$interface_a'
|
|
|
|
}
|
2021-10-14 10:02:05 -04:00
|
|
|
)
|
2021-10-13 09:46:17 -04:00
|
|
|
interface_a = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
query_params={
|
2021-10-14 10:02:05 -04:00
|
|
|
'kind': 'wireless',
|
|
|
|
'device_id': '$device_a',
|
2021-10-13 11:48:15 -04:00
|
|
|
},
|
2021-10-14 10:02:05 -04:00
|
|
|
disabled_indicator='_occupied',
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Interface')
|
2021-10-21 14:11:11 -04:00
|
|
|
)
|
|
|
|
site_b = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Site'),
|
2021-10-21 14:11:11 -04:00
|
|
|
initial_params={
|
|
|
|
'devices': '$device_b',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
location_b = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
2022-04-18 09:02:03 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site_b',
|
|
|
|
},
|
2021-10-21 14:11:11 -04:00
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Location'),
|
2021-10-21 14:11:11 -04:00
|
|
|
initial_params={
|
|
|
|
'devices': '$device_b',
|
|
|
|
}
|
2021-10-13 09:46:17 -04:00
|
|
|
)
|
2021-10-14 10:02:05 -04:00
|
|
|
device_b = DynamicModelChoiceField(
|
|
|
|
queryset=Device.objects.all(),
|
2021-10-21 14:11:11 -04:00
|
|
|
query_params={
|
|
|
|
'site_id': '$site_b',
|
|
|
|
'location_id': '$location_b',
|
|
|
|
},
|
2021-10-20 13:34:39 -04:00
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Device'),
|
2021-10-15 11:35:10 -04:00
|
|
|
initial_params={
|
|
|
|
'interfaces': '$interface_b'
|
|
|
|
}
|
2021-10-14 10:02:05 -04:00
|
|
|
)
|
2021-10-13 09:46:17 -04:00
|
|
|
interface_b = DynamicModelChoiceField(
|
|
|
|
queryset=Interface.objects.all(),
|
|
|
|
query_params={
|
2021-10-14 10:02:05 -04:00
|
|
|
'kind': 'wireless',
|
|
|
|
'device_id': '$device_b',
|
2021-10-13 11:48:15 -04:00
|
|
|
},
|
2021-10-14 10:02:05 -04:00
|
|
|
disabled_indicator='_occupied',
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Interface')
|
2021-10-13 09:46:17 -04:00
|
|
|
)
|
2022-11-04 08:28:09 -04:00
|
|
|
comments = CommentField()
|
2021-10-13 09:46:17 -04:00
|
|
|
|
2022-01-31 15:52:36 -05:00
|
|
|
fieldsets = (
|
|
|
|
('Side A', ('site_a', 'location_a', 'device_a', 'interface_a')),
|
|
|
|
('Side B', ('site_b', 'location_b', 'device_b', 'interface_b')),
|
|
|
|
('Link', ('status', 'ssid', 'description', 'tags')),
|
2022-06-27 11:30:52 -04:00
|
|
|
('Tenancy', ('tenant_group', 'tenant')),
|
2022-01-31 15:52:36 -05:00
|
|
|
('Authentication', ('auth_type', 'auth_cipher', 'auth_psk')),
|
|
|
|
)
|
|
|
|
|
2021-10-13 09:46:17 -04:00
|
|
|
class Meta:
|
|
|
|
model = WirelessLink
|
|
|
|
fields = [
|
2021-10-21 14:11:11 -04:00
|
|
|
'site_a', 'location_a', 'device_a', 'interface_a', 'site_b', 'location_b', 'device_b', 'interface_b',
|
2022-11-04 08:28:09 -04:00
|
|
|
'status', 'ssid', 'tenant_group', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'description',
|
|
|
|
'comments', 'tags',
|
2021-10-13 09:46:17 -04:00
|
|
|
]
|
2021-10-13 14:31:30 -04:00
|
|
|
widgets = {
|
2023-04-24 11:13:28 -05:00
|
|
|
'auth_psk': PasswordInput(
|
|
|
|
render_value=True,
|
|
|
|
attrs={'data-toggle': 'password'}
|
|
|
|
),
|
2021-10-13 14:31:30 -04:00
|
|
|
}
|
2021-10-21 14:11:11 -04:00
|
|
|
labels = {
|
|
|
|
'auth_type': 'Type',
|
|
|
|
'auth_cipher': 'Cipher',
|
|
|
|
}
|