netbox/netbox/wireless/forms/bulk_import.py
Jason Novinger c0b019b735 Adds WirelessLANGroup.comments to all the required places
- [x] 1. Add the field to the model class
- [x] 2. Generate and run database migrations
- [NA] 3. Add validation logic to clean()
- [NA] 4. Update relevant querysets
- [x] 5. Update API serializer
- [x] 6. Add fields to forms
    - [x] wireless.forms.model_forms, create/edit (e.g. model_forms.py)
    - [x] wireless.forms.bulk_edit, bulk edit
    - [x] wireless.forms.bulk_import, CSV import
    - [NA] filter (UI and API)
- [x] 7. Extend object filter set
- [NA] 8. Add column to object table (Note: was already present)
- [x] 9. Update the SearchIndex
- [x] 10. Update the UI templates
- [x] 11. Create/extend test cases
    - [NA] models
    - [x] views
    - [NA] forms
    - [x] filtersets
    - [x] api
- [NA] 12. Update the model's documentation
2025-03-13 11:52:06 -05:00

133 lines
3.8 KiB
Python

from django.utils.translation import gettext_lazy as _
from dcim.choices import LinkStatusChoices
from dcim.forms.mixins import ScopedImportForm
from dcim.models import Interface
from ipam.models import VLAN
from netbox.choices import *
from netbox.forms import NetBoxModelImportForm
from tenancy.models import Tenant
from utilities.forms.fields import CSVChoiceField, CSVModelChoiceField, SlugField
from wireless.choices import *
from wireless.models import *
__all__ = (
'WirelessLANImportForm',
'WirelessLANGroupImportForm',
'WirelessLinkImportForm',
)
class WirelessLANGroupImportForm(NetBoxModelImportForm):
parent = CSVModelChoiceField(
label=_('Parent'),
queryset=WirelessLANGroup.objects.all(),
required=False,
to_field_name='name',
help_text=_('Parent group')
)
slug = SlugField()
class Meta:
model = WirelessLANGroup
fields = ('name', 'slug', 'parent', 'description', 'tags', 'comments')
class WirelessLANImportForm(ScopedImportForm, NetBoxModelImportForm):
group = CSVModelChoiceField(
label=_('Group'),
queryset=WirelessLANGroup.objects.all(),
required=False,
to_field_name='name',
help_text=_('Assigned group')
)
status = CSVChoiceField(
label=_('Status'),
choices=WirelessLANStatusChoices,
help_text=_('Operational status')
)
vlan = CSVModelChoiceField(
label=_('VLAN'),
queryset=VLAN.objects.all(),
required=False,
to_field_name='name',
help_text=_('Bridged VLAN')
)
tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(),
required=False,
to_field_name='name',
help_text=_('Assigned tenant')
)
auth_type = CSVChoiceField(
label=_('Authentication type'),
choices=WirelessAuthTypeChoices,
required=False,
help_text=_('Authentication type')
)
auth_cipher = CSVChoiceField(
label=_('Authentication cipher'),
choices=WirelessAuthCipherChoices,
required=False,
help_text=_('Authentication cipher')
)
class Meta:
model = WirelessLAN
fields = (
'ssid', 'group', 'status', 'vlan', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'scope_type',
'scope_id', 'description', 'comments', 'tags',
)
labels = {
'scope_id': _('Scope ID'),
}
class WirelessLinkImportForm(NetBoxModelImportForm):
status = CSVChoiceField(
label=_('Status'),
choices=LinkStatusChoices,
help_text=_('Connection status')
)
interface_a = CSVModelChoiceField(
label=_('Interface A'),
queryset=Interface.objects.all()
)
interface_b = CSVModelChoiceField(
label=_('Interface B'),
queryset=Interface.objects.all()
)
tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(),
required=False,
to_field_name='name',
help_text=_('Assigned tenant')
)
auth_type = CSVChoiceField(
label=_('Authentication type'),
choices=WirelessAuthTypeChoices,
required=False,
help_text=_('Authentication type')
)
auth_cipher = CSVChoiceField(
label=_('Authentication cipher'),
choices=WirelessAuthCipherChoices,
required=False,
help_text=_('Authentication cipher')
)
distance_unit = CSVChoiceField(
label=_('Distance unit'),
choices=DistanceUnitChoices,
required=False,
help_text=_('Distance unit')
)
class Meta:
model = WirelessLink
fields = (
'interface_a', 'interface_b', 'ssid', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk',
'distance', 'distance_unit', 'description', 'comments', 'tags',
)