2016-07-26 14:58:37 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
from netbox.tables import NetBoxTable, columns
|
2022-01-27 15:00:10 -05:00
|
|
|
from utilities.tables import linkify_phone
|
2021-10-18 11:45:05 -04:00
|
|
|
from .models import *
|
2016-07-26 14:58:37 -04:00
|
|
|
|
2021-09-17 15:37:19 -04:00
|
|
|
__all__ = (
|
2021-10-18 11:45:05 -04:00
|
|
|
'ContactAssignmentTable',
|
|
|
|
'ContactGroupTable',
|
|
|
|
'ContactRoleTable',
|
|
|
|
'ContactTable',
|
2021-09-17 15:37:19 -04:00
|
|
|
'TenantColumn',
|
|
|
|
'TenantGroupTable',
|
|
|
|
'TenantTable',
|
|
|
|
)
|
|
|
|
|
2021-03-04 16:07:55 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Table columns
|
|
|
|
#
|
|
|
|
|
|
|
|
class TenantColumn(tables.TemplateColumn):
|
|
|
|
"""
|
2021-04-02 16:59:53 -04:00
|
|
|
Include the tenant description.
|
2021-03-04 16:07:55 -05:00
|
|
|
"""
|
|
|
|
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 %}
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(template_code=self.template_code, *args, **kwargs)
|
|
|
|
|
|
|
|
def value(self, value):
|
2021-04-05 11:18:30 -04:00
|
|
|
return str(value) if value else None
|
2018-01-30 11:57:21 -05:00
|
|
|
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
#
|
2021-10-18 11:45:05 -04:00
|
|
|
# Tenants
|
2016-07-26 14:58:37 -04:00
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class TenantGroupTable(NetBoxTable):
|
2022-01-27 15:00:10 -05:00
|
|
|
name = columns.MPTTColumn(
|
2021-03-26 15:07:29 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tenant_count = columns.LinkedCountColumn(
|
2020-09-25 12:42:17 -04:00
|
|
|
viewname='tenancy:tenant_list',
|
2021-04-05 11:47:25 -04:00
|
|
|
url_params={'group_id': 'pk'},
|
2020-03-11 20:20:04 -04:00
|
|
|
verbose_name='Tenants'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='tenancy:tenantgroup_list'
|
|
|
|
)
|
2016-07-26 14:58:37 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2016-07-26 14:58:37 -04:00
|
|
|
model = TenantGroup
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'created', 'last_updated', 'actions',
|
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'tenant_count', 'description')
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class TenantTable(NetBoxTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-09-28 16:28:11 -04:00
|
|
|
group = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
comments = columns.MarkdownColumn()
|
|
|
|
tags = columns.TagColumn(
|
2020-05-06 14:42:51 -04:00
|
|
|
url_name='tenancy:tenant_list'
|
|
|
|
)
|
2016-07-26 14:58:37 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2016-07-26 14:58:37 -04:00
|
|
|
model = Tenant
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = ('pk', 'id', 'name', 'slug', 'group', 'description', 'comments', 'tags', 'created', 'last_updated',)
|
2020-04-29 11:34:51 -04:00
|
|
|
default_columns = ('pk', 'name', 'group', 'description')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Contacts
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ContactGroupTable(NetBoxTable):
|
2022-01-27 15:00:10 -05:00
|
|
|
name = columns.MPTTColumn(
|
2021-10-18 11:45:05 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
contact_count = columns.LinkedCountColumn(
|
2021-10-18 11:45:05 -04:00
|
|
|
viewname='tenancy:contact_list',
|
|
|
|
url_params={'role_id': 'pk'},
|
|
|
|
verbose_name='Contacts'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='tenancy:contactgroup_list'
|
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-10-18 11:45:05 -04:00
|
|
|
model = ContactGroup
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'name', 'contact_count', 'description', 'slug', 'tags', 'created', 'last_updated', 'actions',
|
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'contact_count', 'description')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ContactRoleTable(NetBoxTable):
|
2021-10-18 11:45:05 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-10-18 11:45:05 -04:00
|
|
|
model = ContactRole
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = ('pk', 'name', 'description', 'slug', 'created', 'last_updated', 'actions')
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'description')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ContactTable(NetBoxTable):
|
2021-10-18 11:45:05 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
group = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-12-03 10:51:24 -05:00
|
|
|
phone = tables.Column(
|
|
|
|
linkify=linkify_phone,
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
comments = columns.MarkdownColumn()
|
2021-10-18 15:30:28 -04:00
|
|
|
assignment_count = tables.Column(
|
|
|
|
verbose_name='Assignments'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-18 11:45:05 -04:00
|
|
|
url_name='tenancy:tenant_list'
|
|
|
|
)
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-10-18 11:45:05 -04:00
|
|
|
model = Contact
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'name', 'group', 'title', 'phone', 'email', 'address', 'comments', 'assignment_count', 'tags',
|
|
|
|
'created', 'last_updated',
|
|
|
|
)
|
2021-10-18 15:30:28 -04:00
|
|
|
default_columns = ('pk', 'name', 'group', 'assignment_count', 'title', 'phone', 'email')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ContactAssignmentTable(NetBoxTable):
|
2022-01-27 15:00:10 -05:00
|
|
|
content_type = columns.ContentTypeColumn(
|
2021-10-18 15:30:28 -04:00
|
|
|
verbose_name='Object Type'
|
|
|
|
)
|
|
|
|
object = tables.Column(
|
|
|
|
linkify=True,
|
|
|
|
orderable=False
|
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
contact = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-10-18 15:30:28 -04:00
|
|
|
role = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
actions = columns.ActionsColumn(
|
2022-01-07 11:56:18 -05:00
|
|
|
sequence=('edit', 'delete')
|
2021-11-04 14:01:07 -04:00
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-10-18 11:45:05 -04:00
|
|
|
model = ContactAssignment
|
2021-11-04 14:01:07 -04:00
|
|
|
fields = ('pk', 'content_type', 'object', 'contact', 'role', 'priority', 'actions')
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'content_type', 'object', 'contact', 'role', 'priority')
|