15106 rename length -> distance

This commit is contained in:
Arthur Hanson 2024-06-14 15:37:45 -07:00
parent 1165fe4560
commit a72f982fcc
18 changed files with 62 additions and 95 deletions

View File

@ -41,6 +41,6 @@ The security cipher used to apply wireless authentication. Options include:
The security key configured on each client to grant access to the secured wireless LAN. This applies only to certain authentication types. The security key configured on each client to grant access to the secured wireless LAN. This applies only to certain authentication types.
### Length ### Distance
The numeric length of the link, including a unit designation (e.g. 100 meters or 25 feet). The numeric distance of the link, including a unit designation (e.g. 100 meters or 25 feet).

View File

@ -656,11 +656,6 @@ class CableForm(TenancyForm, NetBoxModelForm):
'a_terminations_type', 'b_terminations_type', 'type', 'status', 'tenant_group', 'tenant', 'label', 'color', 'a_terminations_type', 'b_terminations_type', 'type', 'status', 'tenant_group', 'tenant', 'label', 'color',
'length', 'length_unit', 'description', 'comments', 'tags', 'length', 'length_unit', 'description', 'comments', 'tags',
] ]
error_messages = {
'length': {
'max_value': _('Maximum length is 32767 (any unit)')
}
}
class PowerPanelForm(NetBoxModelForm): class PowerPanelForm(NetBoxModelForm):

View File

@ -393,8 +393,8 @@ class CableTraceSVG:
labels = [f"{cable}"] if len(links) > 2 else [f"Wireless {cable}", cable.get_status_display()] labels = [f"{cable}"] if len(links) > 2 else [f"Wireless {cable}", cable.get_status_display()]
if cable.ssid: if cable.ssid:
description.append(f"{cable.ssid}") description.append(f"{cable.ssid}")
if cable.length and cable.length_unit: if cable.distance and cable.distance_unit:
description.append(f"{cable.length} {cable.get_length_unit_display()}") description.append(f"{cable.distance} {cable.get_distance_unit_display()}")
near = [term for term in near_terminations if term.object == cable.interface_a] near = [term for term in near_terminations if term.object == cable.interface_a]
far = [term for term in far_terminations if term.object == cable.interface_b] far = [term for term in far_terminations if term.object == cable.interface_b]
if not (near and far): if not (near and far):

View File

@ -37,8 +37,8 @@
<tr> <tr>
<th scope="row">{% trans "Length" %}</th> <th scope="row">{% trans "Length" %}</th>
<td> <td>
{% if object.length is not None %} {% if object.distance is not None %}
{{ object.length|floatformat }} {{ object.get_length_unit_display }} {{ object.distance|floatformat }} {{ object.get_distance_unit_display }}
{% else %} {% else %}
{{ ''|placeholder }} {{ ''|placeholder }}
{% endif %} {% endif %}

View File

@ -21,13 +21,13 @@ class WirelessLinkSerializer(NetBoxModelSerializer):
tenant = TenantSerializer(nested=True, required=False, allow_null=True) tenant = TenantSerializer(nested=True, required=False, allow_null=True)
auth_type = ChoiceField(choices=WirelessAuthTypeChoices, required=False, allow_blank=True) auth_type = ChoiceField(choices=WirelessAuthTypeChoices, required=False, allow_blank=True)
auth_cipher = ChoiceField(choices=WirelessAuthCipherChoices, required=False, allow_blank=True) auth_cipher = ChoiceField(choices=WirelessAuthCipherChoices, required=False, allow_blank=True)
length_unit = ChoiceField(choices=WirelessLinkLengthUnitChoices, allow_blank=True, required=False, allow_null=True) distance_unit = ChoiceField(choices=WirelessLinkDistanceUnitChoices, allow_blank=True, required=False, allow_null=True)
class Meta: class Meta:
model = WirelessLink model = WirelessLink
fields = [ fields = [
'id', 'url', 'display', 'interface_a', 'interface_b', 'ssid', 'status', 'tenant', 'auth_type', 'id', 'url', 'display', 'interface_a', 'interface_b', 'ssid', 'status', 'tenant', 'auth_type',
'auth_cipher', 'auth_psk', 'length', 'length_unit', 'description', 'comments', 'tags', 'custom_fields', 'auth_cipher', 'auth_psk', 'distance', 'distance_unit', 'description', 'comments', 'tags', 'custom_fields',
'created', 'last_updated', 'created', 'last_updated',
] ]
brief_fields = ('id', 'url', 'display', 'ssid', 'description') brief_fields = ('id', 'url', 'display', 'ssid', 'description')

View File

@ -483,7 +483,7 @@ class WirelessAuthCipherChoices(ChoiceSet):
) )
class WirelessLinkLengthUnitChoices(ChoiceSet): class WirelessLinkDistanceUnitChoices(ChoiceSet):
# Metric # Metric
UNIT_KILOMETER = 'km' UNIT_KILOMETER = 'km'

View File

@ -105,7 +105,7 @@ class WirelessLinkFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
class Meta: class Meta:
model = WirelessLink model = WirelessLink
fields = ('id', 'ssid', 'auth_psk', 'length', 'length_unit', 'description') fields = ('id', 'ssid', 'auth_psk', 'distance', 'distance_unit', 'description')
def search(self, queryset, name, value): def search(self, queryset, name, value):
if not value.strip(): if not value.strip():

View File

@ -125,14 +125,14 @@ class WirelessLinkBulkEditForm(NetBoxModelBulkEditForm):
required=False, required=False,
label=_('Pre-shared key') label=_('Pre-shared key')
) )
length = forms.DecimalField( distance = forms.DecimalField(
label=_('Length'), label=_('Distance'),
min_value=0, min_value=0,
required=False required=False
) )
length_unit = forms.ChoiceField( distance_unit = forms.ChoiceField(
label=_('Length unit'), label=_('Distance unit'),
choices=add_blank_choice(WirelessLinkLengthUnitChoices), choices=add_blank_choice(WirelessLinkDistanceUnitChoices),
required=False, required=False,
initial='' initial=''
) )
@ -147,7 +147,7 @@ class WirelessLinkBulkEditForm(NetBoxModelBulkEditForm):
fieldsets = ( fieldsets = (
FieldSet('ssid', 'status', 'tenant', 'description'), FieldSet('ssid', 'status', 'tenant', 'description'),
FieldSet('auth_type', 'auth_cipher', 'auth_psk', name=_('Authentication')), FieldSet('auth_type', 'auth_cipher', 'auth_psk', name=_('Authentication')),
FieldSet('length', 'length_unit', name=_('Attributes')), FieldSet('distance', 'distance_unit', name=_('Attributes')),
) )
nullable_fields = ( nullable_fields = (
'ssid', 'tenant', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'length', 'comments', 'ssid', 'tenant', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'length', 'comments',

View File

@ -112,16 +112,16 @@ class WirelessLinkImportForm(NetBoxModelImportForm):
required=False, required=False,
help_text=_('Authentication cipher') help_text=_('Authentication cipher')
) )
length_unit = CSVChoiceField( distance_unit = CSVChoiceField(
label=_('Length unit'), label=_('Length unit'),
choices=WirelessLinkLengthUnitChoices, choices=WirelessLinkDistanceUnitChoices,
required=False, required=False,
help_text=_('Length unit') help_text=_('Distance unit')
) )
class Meta: class Meta:
model = WirelessLink model = WirelessLink
fields = ( fields = (
'interface_a', 'interface_b', 'ssid', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'interface_a', 'interface_b', 'ssid', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk',
'length', 'length_unit', 'description', 'comments', 'tags', 'distance', 'distance_unit', 'description', 'comments', 'tags',
) )

View File

@ -98,13 +98,13 @@ class WirelessLinkFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
label=_('Pre-shared key'), label=_('Pre-shared key'),
required=False required=False
) )
length = forms.DecimalField( distance = forms.DecimalField(
label=_('Length'), label=_('Distance'),
required=False, required=False,
) )
length_unit = forms.ChoiceField( distance_unit = forms.ChoiceField(
label=_('Length unit'), label=_('Distance unit'),
choices=add_blank_choice(WirelessLinkLengthUnitChoices), choices=add_blank_choice(WirelessLinkDistanceUnitChoices),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)

View File

@ -169,7 +169,7 @@ class WirelessLinkForm(TenancyForm, NetBoxModelForm):
fields = [ fields = [
'site_a', 'location_a', 'device_a', 'interface_a', 'site_b', 'location_b', 'device_b', 'interface_b', 'site_a', 'location_a', 'device_a', 'interface_a', 'site_b', 'location_b', 'device_b', 'interface_b',
'status', 'ssid', 'tenant_group', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'status', 'ssid', 'tenant_group', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk',
'length', 'length_unit', 'description', 'comments', 'tags', 'distance', 'distance_unit', 'description', 'comments', 'tags',
] ]
widgets = { widgets = {
'auth_psk': PasswordInput( 'auth_psk': PasswordInput(
@ -181,8 +181,3 @@ class WirelessLinkForm(TenancyForm, NetBoxModelForm):
'auth_type': 'Type', 'auth_type': 'Type',
'auth_cipher': 'Cipher', 'auth_cipher': 'Cipher',
} }
error_messages = {
'length': {
'max_value': _('Maximum length is 32767 (any unit)')
}
}

View File

@ -1,28 +0,0 @@
# Generated by Django 5.0.6 on 2024-06-12 18:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wireless', '0001_squashed_0008'),
]
operations = [
migrations.AddField(
model_name='wirelesslink',
name='_abs_length',
field=models.DecimalField(blank=True, decimal_places=4, max_digits=10, null=True),
),
migrations.AddField(
model_name='wirelesslink',
name='length',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True),
),
migrations.AddField(
model_name='wirelesslink',
name='length_unit',
field=models.CharField(blank=True, max_length=50),
),
]

View File

@ -161,21 +161,21 @@ class WirelessLink(WirelessAuthenticationBase, PrimaryModel):
choices=LinkStatusChoices, choices=LinkStatusChoices,
default=LinkStatusChoices.STATUS_CONNECTED default=LinkStatusChoices.STATUS_CONNECTED
) )
length = models.DecimalField( distance = models.DecimalField(
verbose_name=_('length'), verbose_name=_('distance'),
max_digits=8, max_digits=8,
decimal_places=2, decimal_places=2,
blank=True, blank=True,
null=True null=True
) )
length_unit = models.CharField( distance_unit = models.CharField(
verbose_name=_('length unit'), verbose_name=_('distance unit'),
max_length=50, max_length=50,
choices=WirelessLinkLengthUnitChoices, choices=WirelessLinkDistanceUnitChoices,
blank=True, blank=True,
) )
# Stores the normalized length (in meters) for database ordering # Stores the normalized length (in meters) for database ordering
_abs_length = models.DecimalField( _abs_distance = models.DecimalField(
max_digits=10, max_digits=10,
decimal_places=4, decimal_places=4,
blank=True, blank=True,
@ -229,6 +229,11 @@ class WirelessLink(WirelessAuthenticationBase, PrimaryModel):
return LinkStatusChoices.colors.get(self.status) return LinkStatusChoices.colors.get(self.status)
def clean(self): def clean(self):
super().clean()
# Validate distance and distance_unit
if self.distance is not None and not self.distance_unit:
raise ValidationError(_("Must specify a unit when setting a wireless distance"))
# Validate interface types # Validate interface types
if self.interface_a.type not in WIRELESS_IFACE_TYPES: if self.interface_a.type not in WIRELESS_IFACE_TYPES:
@ -247,9 +252,9 @@ class WirelessLink(WirelessAuthenticationBase, PrimaryModel):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
# Store the given length (if any) in meters for use in database ordering # Store the given length (if any) in meters for use in database ordering
if self.length is not None and self.length_unit: if self.length is not None and self.length_unit:
self._abs_length = to_meters(self.length, self.length_unit) self._abs_distance = to_meters(self.length, self.length_unit)
else: else:
self._abs_length = None self._abs_distance = None
# Clear length_unit if no length is defined # Clear length_unit if no length is defined
if self.length is None: if self.length is None:

View File

@ -1,4 +1,4 @@
WIRELESS_LINK_LENGTH = """ WIRELESS_LINK_DISTANCE = """
{% load helpers %} {% load helpers %}
{% if record.length %}{{ record.length|floatformat:"-2" }} {{ record.length_unit }}{% endif %} {% if record.distance %}{{ record.distance|floatformat:"-2" }} {{ record.distance_unit }}{% endif %}
""" """

View File

@ -4,7 +4,7 @@ import django_tables2 as tables
from netbox.tables import NetBoxTable, columns from netbox.tables import NetBoxTable, columns
from tenancy.tables import TenancyColumnsMixin from tenancy.tables import TenancyColumnsMixin
from wireless.models import * from wireless.models import *
from .template_code import WIRELESS_LINK_LENGTH from .template_code import WIRELESS_LINK_DISTANCE
__all__ = ( __all__ = (
'WirelessLinkTable', 'WirelessLinkTable',
@ -37,9 +37,9 @@ class WirelessLinkTable(TenancyColumnsMixin, NetBoxTable):
verbose_name=_('Interface B'), verbose_name=_('Interface B'),
linkify=True linkify=True
) )
length = columns.TemplateColumn( distance = columns.TemplateColumn(
template_code=WIRELESS_LINK_LENGTH, template_code=WIRELESS_LINK_DISTANCE,
order_by=('_abs_length', 'length_unit') order_by=('_abs_distance', 'distance_unit')
) )
tags = columns.TagColumn( tags = columns.TagColumn(
url_name='wireless:wirelesslink_list' url_name='wireless:wirelesslink_list'
@ -49,7 +49,7 @@ class WirelessLinkTable(TenancyColumnsMixin, NetBoxTable):
model = WirelessLink model = WirelessLink
fields = ( fields = (
'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'tenant', 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'tenant',
'tenant_group', 'length', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'tags', 'tenant_group', 'distance', 'description', 'auth_type', 'auth_cipher', 'auth_psk', 'tags',
'created', 'last_updated', 'created', 'last_updated',
) )
default_columns = ( default_columns = (

View File

@ -113,8 +113,8 @@ class WirelessLinkTest(APIViewTestCases.APIViewTestCase):
brief_fields = ['description', 'display', 'id', 'ssid', 'url'] brief_fields = ['description', 'display', 'id', 'ssid', 'url']
bulk_update_data = { bulk_update_data = {
'status': 'planned', 'status': 'planned',
'length': 100, 'distance': 100,
'length_unit': 'm', 'distance_unit': 'm',
} }
@classmethod @classmethod

View File

@ -260,8 +260,8 @@ class WirelessLinkTestCase(TestCase, ChangeLoggedFilterSetTests):
auth_cipher=WirelessAuthCipherChoices.CIPHER_AUTO, auth_cipher=WirelessAuthCipherChoices.CIPHER_AUTO,
auth_psk='PSK1', auth_psk='PSK1',
tenant=tenants[0], tenant=tenants[0],
length=10, distance=10,
length_unit=WirelessLinkLengthUnitChoices.UNIT_FOOT, distance_unit=WirelessLinkDistanceUnitChoices.UNIT_FOOT,
description='foobar1' description='foobar1'
).save() ).save()
WirelessLink( WirelessLink(
@ -273,8 +273,8 @@ class WirelessLinkTestCase(TestCase, ChangeLoggedFilterSetTests):
auth_cipher=WirelessAuthCipherChoices.CIPHER_TKIP, auth_cipher=WirelessAuthCipherChoices.CIPHER_TKIP,
auth_psk='PSK2', auth_psk='PSK2',
tenant=tenants[1], tenant=tenants[1],
length=20, distance=20,
length_unit=WirelessLinkLengthUnitChoices.UNIT_METER, distance_unit=WirelessLinkDistanceUnitChoices.UNIT_METER,
description='foobar2' description='foobar2'
).save() ).save()
WirelessLink( WirelessLink(
@ -285,8 +285,8 @@ class WirelessLinkTestCase(TestCase, ChangeLoggedFilterSetTests):
auth_type=WirelessAuthTypeChoices.TYPE_WPA_PERSONAL, auth_type=WirelessAuthTypeChoices.TYPE_WPA_PERSONAL,
auth_cipher=WirelessAuthCipherChoices.CIPHER_AES, auth_cipher=WirelessAuthCipherChoices.CIPHER_AES,
auth_psk='PSK3', auth_psk='PSK3',
length=30, distance=30,
length_unit=WirelessLinkLengthUnitChoices.UNIT_METER, distance_unit=WirelessLinkDistanceUnitChoices.UNIT_METER,
tenant=tenants[2], tenant=tenants[2],
).save() ).save()
WirelessLink( WirelessLink(
@ -319,12 +319,12 @@ class WirelessLinkTestCase(TestCase, ChangeLoggedFilterSetTests):
params = {'auth_psk': ['PSK1', 'PSK2']} params = {'auth_psk': ['PSK1', 'PSK2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
def test_length(self): def test_distance(self):
params = {'length': [10, 20]} params = {'distance': [10, 20]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
def test_length_unit(self): def test_distance_unit(self):
params = {'length_unit': WirelessLinkLengthUnitChoices.UNIT_FOOT} params = {'distance_unit': WirelessLinkDistanceUnitChoices.UNIT_FOOT}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
def test_description(self): def test_description(self):

View File

@ -160,8 +160,8 @@ class WirelessLinkTestCase(ViewTestCases.PrimaryObjectViewTestCase):
'interface_a': interfaces[6].pk, 'interface_a': interfaces[6].pk,
'interface_b': interfaces[7].pk, 'interface_b': interfaces[7].pk,
'status': LinkStatusChoices.STATUS_PLANNED, 'status': LinkStatusChoices.STATUS_PLANNED,
'length': 100, 'distance': 100,
'length_unit': WirelessLinkLengthUnitChoices.UNIT_FOOT, 'distance_unit': WirelessLinkDistanceUnitChoices.UNIT_FOOT,
'tenant': tenants[1].pk, 'tenant': tenants[1].pk,
'tags': [t.pk for t in tags], 'tags': [t.pk for t in tags],
} }
@ -182,6 +182,6 @@ class WirelessLinkTestCase(ViewTestCases.PrimaryObjectViewTestCase):
cls.bulk_edit_data = { cls.bulk_edit_data = {
'status': LinkStatusChoices.STATUS_PLANNED, 'status': LinkStatusChoices.STATUS_PLANNED,
'length': 50, 'distance': 50,
'length_unit': WirelessLinkLengthUnitChoices.UNIT_METER, 'distance_unit': WirelessLinkDistanceUnitChoices.UNIT_METER,
} }