Closes #18022: Extend linter (ruff) to enforce line length limit (120 chars) (#18067)

* Enable E501 rule
* Configure ruff formatter
* Reformat migration files to fix line length violations
* Fix various E501 errors
* Move table template code to template_code.py & ignore E501 errors
* Reformat raw SQL
This commit is contained in:
Jeremy Stretch
2024-11-21 15:58:11 -05:00
committed by GitHub
parent f08e36e538
commit 343a4af591
200 changed files with 5928 additions and 1670 deletions

View File

@@ -52,9 +52,9 @@ class WirelessLANSerializer(NetBoxModelSerializer):
class Meta:
model = WirelessLAN
fields = [
'id', 'url', 'display_url', 'display', 'ssid', 'description', 'group', 'status', 'vlan', 'scope_type', 'scope_id', 'scope',
'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'description', 'comments', 'tags', 'custom_fields',
'created', 'last_updated',
'id', 'url', 'display_url', 'display', 'ssid', 'description', 'group', 'status', 'vlan', 'scope_type',
'scope_id', 'scope', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'description', 'comments', 'tags',
'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'ssid', 'description')

View File

@@ -76,8 +76,8 @@ class WirelessLANImportForm(ScopedImportForm, NetBoxModelImportForm):
class Meta:
model = WirelessLAN
fields = (
'ssid', 'group', 'status', 'vlan', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'scope_type', 'scope_id',
'description', 'comments', 'tags',
'ssid', 'group', 'status', 'vlan', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'scope_type',
'scope_id', 'description', 'comments', 'tags',
)
labels = {
'scope_id': _('Scope ID'),

View File

@@ -8,7 +8,6 @@ import wireless.models
class Migration(migrations.Migration):
replaces = [
('wireless', '0001_wireless'),
('wireless', '0002_standardize_id_fields'),
@@ -17,7 +16,7 @@ class Migration(migrations.Migration):
('wireless', '0005_wirelesslink_interface_types'),
('wireless', '0006_unique_constraints'),
('wireless', '0007_standardize_description_comments'),
('wireless', '0008_wirelesslan_status')
('wireless', '0008_wirelesslan_status'),
]
dependencies = [
@@ -33,7 +32,10 @@ class Migration(migrations.Migration):
fields=[
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
(
'custom_field_data',
models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('name', models.CharField(max_length=100, unique=True)),
('slug', models.SlugField(max_length=100, unique=True)),
@@ -43,7 +45,16 @@ class Migration(migrations.Migration):
('rght', models.PositiveIntegerField(editable=False)),
('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
('level', models.PositiveIntegerField(editable=False)),
('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='wireless.wirelesslangroup')),
(
'parent',
mptt.fields.TreeForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='children',
to='wireless.wirelesslangroup',
),
),
],
options={
'ordering': ('name', 'pk'),
@@ -56,17 +67,43 @@ class Migration(migrations.Migration):
fields=[
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
(
'custom_field_data',
models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('ssid', models.CharField(max_length=32)),
('group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='wireless_lans', to='wireless.wirelesslangroup')),
(
'group',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='wireless_lans',
to='wireless.wirelesslangroup',
),
),
('description', models.CharField(blank=True, max_length=200)),
('auth_cipher', models.CharField(blank=True, max_length=50)),
('auth_psk', models.CharField(blank=True, max_length=64)),
('auth_type', models.CharField(blank=True, max_length=50)),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
('vlan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='ipam.vlan')),
('tenant', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='wireless_lans', to='tenancy.tenant')),
(
'vlan',
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='ipam.vlan'
),
),
(
'tenant',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name='wireless_lans',
to='tenancy.tenant',
),
),
],
options={
'verbose_name': 'Wireless LAN',
@@ -78,7 +115,10 @@ class Migration(migrations.Migration):
fields=[
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
(
'custom_field_data',
models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('ssid', models.CharField(blank=True, max_length=32)),
('status', models.CharField(default='connected', max_length=50)),
@@ -86,12 +126,55 @@ class Migration(migrations.Migration):
('auth_cipher', models.CharField(blank=True, max_length=50)),
('auth_psk', models.CharField(blank=True, max_length=64)),
('auth_type', models.CharField(blank=True, max_length=50)),
('_interface_a_device', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='dcim.device')),
('_interface_b_device', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='dcim.device')),
('interface_a', models.ForeignKey(limit_choices_to=wireless.models.get_wireless_interface_types, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='dcim.interface')),
('interface_b', models.ForeignKey(limit_choices_to=wireless.models.get_wireless_interface_types, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='dcim.interface')),
(
'_interface_a_device',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='+',
to='dcim.device',
),
),
(
'_interface_b_device',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='+',
to='dcim.device',
),
),
(
'interface_a',
models.ForeignKey(
limit_choices_to=wireless.models.get_wireless_interface_types,
on_delete=django.db.models.deletion.PROTECT,
related_name='+',
to='dcim.interface',
),
),
(
'interface_b',
models.ForeignKey(
limit_choices_to=wireless.models.get_wireless_interface_types,
on_delete=django.db.models.deletion.PROTECT,
related_name='+',
to='dcim.interface',
),
),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
('tenant', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='wireless_links', to='tenancy.tenant')),
(
'tenant',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name='wireless_links',
to='tenancy.tenant',
),
),
],
options={
'ordering': ['pk'],
@@ -100,11 +183,15 @@ class Migration(migrations.Migration):
),
migrations.AddConstraint(
model_name='wirelesslangroup',
constraint=models.UniqueConstraint(fields=('parent', 'name'), name='wireless_wirelesslangroup_unique_parent_name'),
constraint=models.UniqueConstraint(
fields=('parent', 'name'), name='wireless_wirelesslangroup_unique_parent_name'
),
),
migrations.AddConstraint(
model_name='wirelesslink',
constraint=models.UniqueConstraint(fields=('interface_a', 'interface_b'), name='wireless_wirelesslink_unique_interfaces'),
constraint=models.UniqueConstraint(
fields=('interface_a', 'interface_b'), name='wireless_wirelesslink_unique_interfaces'
),
),
migrations.AddField(
model_name='wirelesslan',

View File

@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wireless', '0001_squashed_0008'),
]

View File

@@ -16,7 +16,6 @@ def set_null_values(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('wireless', '0009_wirelesslink_distance'),
]
@@ -47,8 +46,5 @@ class Migration(migrations.Migration):
name='distance_unit',
field=models.CharField(blank=True, max_length=50, null=True),
),
migrations.RunPython(
code=set_null_values,
reverse_code=migrations.RunPython.noop
),
migrations.RunPython(code=set_null_values, reverse_code=migrations.RunPython.noop),
]

View File

@@ -5,7 +5,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('dcim', '0196_qinq_svlan'),

View File

@@ -5,7 +5,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dcim', '0196_qinq_svlan'),
('wireless', '0011_wirelesslan__location_wirelesslan__region_and_more'),

View File

@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wireless', '0012_alter_wirelesslan__location_and_more'),
('dcim', '0197_natural_sort_collation'),

View File

@@ -72,7 +72,8 @@ class WirelessLANTable(TenancyColumnsMixin, NetBoxTable):
model = WirelessLAN
fields = (
'pk', 'ssid', 'group', 'status', 'tenant', 'tenant_group', 'vlan', 'interface_count', 'auth_type',
'auth_cipher', 'auth_psk', 'scope', 'scope_type', 'description', 'comments', 'tags', 'created', 'last_updated',
'auth_cipher', 'auth_psk', 'scope', 'scope_type', 'description', 'comments', 'tags', 'created',
'last_updated',
)
default_columns = ('pk', 'ssid', 'group', 'status', 'description', 'vlan', 'auth_type', 'interface_count')

View File

@@ -27,8 +27,18 @@ class WirelessLANGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
group.save()
groups = (
WirelessLANGroup(name='Wireless LAN Group 1A', slug='wireless-lan-group-1a', parent=parent_groups[0], description='foobar1'),
WirelessLANGroup(name='Wireless LAN Group 1B', slug='wireless-lan-group-1b', parent=parent_groups[0], description='foobar2'),
WirelessLANGroup(
name='Wireless LAN Group 1A',
slug='wireless-lan-group-1a',
parent=parent_groups[0],
description='foobar1',
),
WirelessLANGroup(
name='Wireless LAN Group 1B',
slug='wireless-lan-group-1b',
parent=parent_groups[0],
description='foobar2',
),
WirelessLANGroup(name='Wireless LAN Group 2A', slug='wireless-lan-group-2a', parent=parent_groups[1]),
WirelessLANGroup(name='Wireless LAN Group 2B', slug='wireless-lan-group-2b', parent=parent_groups[1]),
WirelessLANGroup(name='Wireless LAN Group 3A', slug='wireless-lan-group-3a', parent=parent_groups[2]),

View File

@@ -113,9 +113,20 @@ class WirelessLANTestCase(ViewTestCases.PrimaryObjectViewTestCase):
cls.csv_data = (
"group,ssid,status,tenant,scope_type,scope_id",
f"Wireless LAN Group 2,WLAN4,{WirelessLANStatusChoices.STATUS_ACTIVE},{tenants[0].name},,",
f"Wireless LAN Group 2,WLAN5,{WirelessLANStatusChoices.STATUS_DISABLED},{tenants[1].name},dcim.site,{sites[0].pk}",
f"Wireless LAN Group 2,WLAN6,{WirelessLANStatusChoices.STATUS_RESERVED},{tenants[2].name},dcim.site,{sites[1].pk}",
"Wireless LAN Group 2,WLAN4,{status},{tenant},,".format(
status=WirelessLANStatusChoices.STATUS_ACTIVE,
tenant=tenants[0].name
),
"Wireless LAN Group 2,WLAN5,{status},{tenant},dcim.site,{site}".format(
status=WirelessLANStatusChoices.STATUS_DISABLED,
tenant=tenants[1].name,
site=sites[0].pk
),
"Wireless LAN Group 2,WLAN6,{status},{tenant},dcim.site,{site}".format(
status=WirelessLANStatusChoices.STATUS_RESERVED,
tenant=tenants[2].name,
site=sites[1].pk
),
)
cls.csv_update_data = (
@@ -157,11 +168,17 @@ class WirelessLinkTestCase(ViewTestCases.PrimaryObjectViewTestCase):
]
Interface.objects.bulk_create(interfaces)
wirelesslink1 = WirelessLink(interface_a=interfaces[0], interface_b=interfaces[1], ssid='LINK1', tenant=tenants[0])
wirelesslink1 = WirelessLink(
interface_a=interfaces[0], interface_b=interfaces[1], ssid='LINK1', tenant=tenants[0]
)
wirelesslink1.save()
wirelesslink2 = WirelessLink(interface_a=interfaces[2], interface_b=interfaces[3], ssid='LINK2', tenant=tenants[0])
wirelesslink2 = WirelessLink(
interface_a=interfaces[2], interface_b=interfaces[3], ssid='LINK2', tenant=tenants[0]
)
wirelesslink2.save()
wirelesslink3 = WirelessLink(interface_a=interfaces[4], interface_b=interfaces[5], ssid='LINK3', tenant=tenants[0])
wirelesslink3 = WirelessLink(
interface_a=interfaces[4], interface_b=interfaces[5], ssid='LINK3', tenant=tenants[0]
)
wirelesslink3.save()
tags = create_tags('Alpha', 'Bravo', 'Charlie')