2021-10-21 14:11:11 -04:00
|
|
|
from dcim.models import Device, Interface, Location, Site
|
2021-10-12 12:27:12 -04:00
|
|
|
from extras.forms import CustomFieldModelForm
|
|
|
|
from extras.models import Tag
|
|
|
|
from ipam.models import VLAN
|
2021-11-18 16:48:29 -05:00
|
|
|
from utilities.forms import DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField, StaticSelect
|
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
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-18 16:19:25 -05:00
|
|
|
class WirelessLANGroupForm(CustomFieldModelForm):
|
2021-10-13 16:40:12 -04:00
|
|
|
parent = DynamicModelChoiceField(
|
|
|
|
queryset=WirelessLANGroup.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
slug = SlugField()
|
2021-10-21 13:19:52 -04:00
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
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
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-11-18 16:19:25 -05:00
|
|
|
class WirelessLANForm(CustomFieldModelForm):
|
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,
|
|
|
|
label='VLAN'
|
2021-10-12 12:27:12 -04:00
|
|
|
)
|
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2021-10-12 17:02:53 -04:00
|
|
|
model = WirelessLAN
|
2021-10-12 12:27:12 -04:00
|
|
|
fields = [
|
2021-10-20 10:58:15 -04:00
|
|
|
'ssid', 'group', 'description', 'vlan', 'auth_type', 'auth_cipher', 'auth_psk', 'tags',
|
2021-10-12 12:27:12 -04:00
|
|
|
]
|
|
|
|
fieldsets = (
|
2021-10-13 16:40:12 -04:00
|
|
|
('Wireless LAN', ('ssid', 'group', 'description', 'tags')),
|
2021-10-12 12:27:12 -04:00
|
|
|
('VLAN', ('vlan',)),
|
2021-10-20 10:58:15 -04:00
|
|
|
('Authentication', ('auth_type', 'auth_cipher', 'auth_psk')),
|
2021-10-12 12:27:12 -04:00
|
|
|
)
|
2021-10-20 10:58:15 -04:00
|
|
|
widgets = {
|
|
|
|
'auth_type': StaticSelect,
|
|
|
|
'auth_cipher': StaticSelect,
|
|
|
|
}
|
2021-10-13 09:46:17 -04:00
|
|
|
|
|
|
|
|
2021-11-18 16:19:25 -05:00
|
|
|
class WirelessLinkForm(CustomFieldModelForm):
|
2021-10-21 14:11:11 -04:00
|
|
|
site_a = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='Site',
|
|
|
|
initial_params={
|
|
|
|
'devices': '$device_a',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
location_a = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='Location',
|
|
|
|
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,
|
2021-10-21 14:11:11 -04: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',
|
2021-10-21 14:11:11 -04:00
|
|
|
label='Interface'
|
|
|
|
)
|
|
|
|
site_b = DynamicModelChoiceField(
|
|
|
|
queryset=Site.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='Site',
|
|
|
|
initial_params={
|
|
|
|
'devices': '$device_b',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
location_b = DynamicModelChoiceField(
|
|
|
|
queryset=Location.objects.all(),
|
|
|
|
required=False,
|
|
|
|
label='Location',
|
|
|
|
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,
|
2021-10-21 14:11:11 -04: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',
|
2021-10-21 14:11:11 -04:00
|
|
|
label='Interface'
|
2021-10-13 09:46:17 -04:00
|
|
|
)
|
|
|
|
tags = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=Tag.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
|
|
|
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',
|
|
|
|
'status', 'ssid', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'tags',
|
2021-10-13 09:46:17 -04:00
|
|
|
]
|
2021-10-20 10:58:15 -04:00
|
|
|
fieldsets = (
|
2021-10-21 14:11:11 -04:00
|
|
|
('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')),
|
2021-10-20 10:58:15 -04:00
|
|
|
('Authentication', ('auth_type', 'auth_cipher', 'auth_psk')),
|
|
|
|
)
|
2021-10-13 14:31:30 -04:00
|
|
|
widgets = {
|
|
|
|
'status': StaticSelect,
|
2021-10-20 10:58:15 -04:00
|
|
|
'auth_type': StaticSelect,
|
|
|
|
'auth_cipher': StaticSelect,
|
2021-10-13 14:31:30 -04:00
|
|
|
}
|
2021-10-21 14:11:11 -04:00
|
|
|
labels = {
|
|
|
|
'auth_type': 'Type',
|
|
|
|
'auth_cipher': 'Cipher',
|
|
|
|
}
|