mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-22 11:38:45 -06:00
* 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:
@@ -6,7 +6,6 @@ import taggit.managers
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
@@ -43,7 +42,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='tenancy.tenantgroup')),
|
||||
(
|
||||
'parent',
|
||||
mptt.fields.TreeForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name='children',
|
||||
to='tenancy.tenantgroup',
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'ordering': ['name'],
|
||||
@@ -60,7 +68,16 @@ class Migration(migrations.Migration):
|
||||
('slug', models.SlugField(max_length=100, unique=True)),
|
||||
('description', models.CharField(blank=True, max_length=200)),
|
||||
('comments', models.TextField(blank=True)),
|
||||
('group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tenants', to='tenancy.tenantgroup')),
|
||||
(
|
||||
'group',
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name='tenants',
|
||||
to='tenancy.tenantgroup',
|
||||
),
|
||||
),
|
||||
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
|
||||
],
|
||||
options={
|
||||
|
||||
@@ -7,7 +7,6 @@ import utilities.json
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
replaces = [
|
||||
('tenancy', '0002_tenant_ordering'),
|
||||
('tenancy', '0003_contacts'),
|
||||
@@ -18,7 +17,7 @@ class Migration(migrations.Migration):
|
||||
('tenancy', '0008_unique_constraints'),
|
||||
('tenancy', '0009_standardize_description_comments'),
|
||||
('tenancy', '0010_tenant_relax_uniqueness'),
|
||||
('tenancy', '0011_contactassignment_tags')
|
||||
('tenancy', '0011_contactassignment_tags'),
|
||||
]
|
||||
|
||||
dependencies = [
|
||||
@@ -37,7 +36,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)),
|
||||
@@ -53,7 +55,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)),
|
||||
('slug', models.SlugField(max_length=100)),
|
||||
@@ -62,7 +67,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='tenancy.contactgroup')),
|
||||
(
|
||||
'parent',
|
||||
mptt.fields.TreeForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name='children',
|
||||
to='tenancy.contactgroup',
|
||||
),
|
||||
),
|
||||
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
|
||||
],
|
||||
options={
|
||||
@@ -75,7 +89,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)),
|
||||
('title', models.CharField(blank=True, max_length=100)),
|
||||
@@ -83,7 +100,16 @@ class Migration(migrations.Migration):
|
||||
('email', models.EmailField(blank=True, max_length=254)),
|
||||
('address', models.CharField(blank=True, max_length=200)),
|
||||
('comments', models.TextField(blank=True)),
|
||||
('group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contacts', to='tenancy.contactgroup')),
|
||||
(
|
||||
'group',
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name='contacts',
|
||||
to='tenancy.contactgroup',
|
||||
),
|
||||
),
|
||||
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
|
||||
('link', models.URLField(blank=True)),
|
||||
],
|
||||
@@ -125,9 +151,24 @@ class Migration(migrations.Migration):
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
|
||||
('object_id', models.PositiveBigIntegerField()),
|
||||
('priority', models.CharField(blank=True, max_length=50)),
|
||||
('contact', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='assignments', to='tenancy.contact')),
|
||||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
|
||||
('role', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='assignments', to='tenancy.contactrole')),
|
||||
(
|
||||
'contact',
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.PROTECT, related_name='assignments', to='tenancy.contact'
|
||||
),
|
||||
),
|
||||
(
|
||||
'content_type',
|
||||
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'),
|
||||
),
|
||||
(
|
||||
'role',
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name='assignments',
|
||||
to='tenancy.contactrole',
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'ordering': ('priority', 'contact'),
|
||||
@@ -140,11 +181,16 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='contactassignment',
|
||||
constraint=models.UniqueConstraint(fields=('content_type', 'object_id', 'contact', 'role'), name='tenancy_contactassignment_unique_object_contact_role'),
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=('content_type', 'object_id', 'contact', 'role'),
|
||||
name='tenancy_contactassignment_unique_object_contact_role',
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='contactgroup',
|
||||
constraint=models.UniqueConstraint(fields=('parent', 'name'), name='tenancy_contactgroup_unique_parent_name'),
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=('parent', 'name'), name='tenancy_contactgroup_unique_parent_name'
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
@@ -163,19 +209,31 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='tenant',
|
||||
constraint=models.UniqueConstraint(fields=('group', 'name'), name='tenancy_tenant_unique_group_name', violation_error_message='Tenant name must be unique per group.'),
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=('group', 'name'),
|
||||
name='tenancy_tenant_unique_group_name',
|
||||
violation_error_message='Tenant name must be unique per group.',
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='tenant',
|
||||
constraint=models.UniqueConstraint(condition=models.Q(('group__isnull', True)), fields=('name',), name='tenancy_tenant_unique_name'),
|
||||
constraint=models.UniqueConstraint(
|
||||
condition=models.Q(('group__isnull', True)), fields=('name',), name='tenancy_tenant_unique_name'
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='tenant',
|
||||
constraint=models.UniqueConstraint(fields=('group', 'slug'), name='tenancy_tenant_unique_group_slug', violation_error_message='Tenant slug must be unique per group.'),
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=('group', 'slug'),
|
||||
name='tenancy_tenant_unique_group_slug',
|
||||
violation_error_message='Tenant slug must be unique per group.',
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='tenant',
|
||||
constraint=models.UniqueConstraint(condition=models.Q(('group__isnull', True)), fields=('slug',), name='tenancy_tenant_unique_slug'),
|
||||
constraint=models.UniqueConstraint(
|
||||
condition=models.Q(('group__isnull', True)), fields=('slug',), name='tenancy_tenant_unique_slug'
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contactassignment',
|
||||
|
||||
@@ -5,7 +5,6 @@ import utilities.json
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0011_contactassignment_tags'),
|
||||
]
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0012_contactassignment_custom_fields'),
|
||||
]
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0013_gfk_indexes'),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
('extras', '0111_rename_content_types'),
|
||||
@@ -25,16 +24,13 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='contactassignment',
|
||||
index=models.Index(
|
||||
fields=['object_type', 'object_id'],
|
||||
name='tenancy_con_object__6f20f7_idx'
|
||||
),
|
||||
index=models.Index(fields=['object_type', 'object_id'], name='tenancy_con_object__6f20f7_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='contactassignment',
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=('object_type', 'object_id', 'contact', 'role'),
|
||||
name='tenancy_contactassignment_unique_object_contact_role'
|
||||
name='tenancy_contactassignment_unique_object_contact_role',
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -11,7 +11,6 @@ def set_null_values(apps, schema_editor):
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0015_contactassignment_rename_content_type'),
|
||||
]
|
||||
@@ -22,8 +21,5 @@ class Migration(migrations.Migration):
|
||||
name='priority',
|
||||
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),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0016_charfield_null_choices'),
|
||||
('dcim', '0197_natural_sort_collation'),
|
||||
|
||||
@@ -2,6 +2,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
import django_tables2 as tables
|
||||
|
||||
from netbox.tables import columns
|
||||
from .template_code import *
|
||||
|
||||
__all__ = (
|
||||
'ContactsColumnMixin',
|
||||
@@ -15,15 +16,7 @@ class TenantColumn(tables.TemplateColumn):
|
||||
"""
|
||||
Include the tenant description.
|
||||
"""
|
||||
template_code = """
|
||||
{% if record.tenant %}
|
||||
<a href="{{ record.tenant.get_absolute_url }}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
|
||||
{% elif record.vrf.tenant %}
|
||||
<a href="{{ record.vrf.tenant.get_absolute_url }}" title="{{ record.vrf.tenant.description }}">{{ record.vrf.tenant }}</a>*
|
||||
{% else %}
|
||||
—
|
||||
{% endif %}
|
||||
"""
|
||||
template_code = TENANT_COLUMN
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(template_code=self.template_code, *args, **kwargs)
|
||||
@@ -36,15 +29,7 @@ class TenantGroupColumn(tables.TemplateColumn):
|
||||
"""
|
||||
Include the tenant group description.
|
||||
"""
|
||||
template_code = """
|
||||
{% if record.tenant and record.tenant.group %}
|
||||
<a href="{{ record.tenant.group.get_absolute_url }}" title="{{ record.tenant.group.description }}">{{ record.tenant.group }}</a>
|
||||
{% elif record.vrf.tenant and record.vrf.tenant.group %}
|
||||
<a href="{{ record.vrf.tenant.group.get_absolute_url }}" title="{{ record.vrf.tenant.group.description }}">{{ record.vrf.tenant.group }}</a>*
|
||||
{% else %}
|
||||
—
|
||||
{% endif %}
|
||||
"""
|
||||
template_code = TENANT_GROUP_COLUMN
|
||||
|
||||
def __init__(self, accessor=tables.A('tenant__group'), *args, **kwargs):
|
||||
if 'verbose_name' not in kwargs:
|
||||
|
||||
19
netbox/tenancy/tables/template_code.py
Normal file
19
netbox/tenancy/tables/template_code.py
Normal file
@@ -0,0 +1,19 @@
|
||||
TENANT_COLUMN = """
|
||||
{% if record.tenant %}
|
||||
<a href="{{ record.tenant.get_absolute_url }}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
|
||||
{% elif record.vrf.tenant %}
|
||||
<a href="{{ record.vrf.tenant.get_absolute_url }}" title="{{ record.vrf.tenant.description }}">{{ record.vrf.tenant }}</a>*
|
||||
{% else %}
|
||||
—
|
||||
{% endif %}
|
||||
"""
|
||||
|
||||
TENANT_GROUP_COLUMN = """
|
||||
{% if record.tenant and record.tenant.group %}
|
||||
<a href="{{ record.tenant.group.get_absolute_url }}" title="{{ record.tenant.group.description }}">{{ record.tenant.group }}</a>
|
||||
{% elif record.vrf.tenant and record.vrf.tenant.group %}
|
||||
<a href="{{ record.vrf.tenant.group.get_absolute_url }}" title="{{ record.vrf.tenant.group.description }}">{{ record.vrf.tenant.group }}</a>*
|
||||
{% else %}
|
||||
—
|
||||
{% endif %}
|
||||
"""
|
||||
@@ -239,9 +239,24 @@ class ContactAssignmentTest(APIViewTestCases.APIViewTestCase):
|
||||
ContactRole.objects.bulk_create(contact_roles)
|
||||
|
||||
contact_assignments = (
|
||||
ContactAssignment(object=sites[0], contact=contacts[0], role=contact_roles[0], priority=ContactPriorityChoices.PRIORITY_PRIMARY),
|
||||
ContactAssignment(object=sites[0], contact=contacts[1], role=contact_roles[1], priority=ContactPriorityChoices.PRIORITY_SECONDARY),
|
||||
ContactAssignment(object=sites[0], contact=contacts[2], role=contact_roles[2], priority=ContactPriorityChoices.PRIORITY_TERTIARY),
|
||||
ContactAssignment(
|
||||
object=sites[0],
|
||||
contact=contacts[0],
|
||||
role=contact_roles[0],
|
||||
priority=ContactPriorityChoices.PRIORITY_PRIMARY,
|
||||
),
|
||||
ContactAssignment(
|
||||
object=sites[0],
|
||||
contact=contacts[1],
|
||||
role=contact_roles[1],
|
||||
priority=ContactPriorityChoices.PRIORITY_SECONDARY,
|
||||
),
|
||||
ContactAssignment(
|
||||
object=sites[0],
|
||||
contact=contacts[2],
|
||||
role=contact_roles[2],
|
||||
priority=ContactPriorityChoices.PRIORITY_TERTIARY,
|
||||
),
|
||||
)
|
||||
ContactAssignment.objects.bulk_create(contact_assignments)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user