1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

171 lines
4.4 KiB
Python
Raw Normal View History

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
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',
)
#
# Table columns
#
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 %}
&mdash;
{% endif %}
"""
def __init__(self, *args, **kwargs):
super().__init__(template_code=self.template_code, *args, **kwargs)
def value(self, value):
return str(value) if value else None
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):
name = columns.MPTTColumn(
linkify=True
)
tenant_count = columns.LinkedCountColumn(
viewname='tenancy:tenant_list',
url_params={'group_id': 'pk'},
verbose_name='Tenants'
)
tags = columns.TagColumn(
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',
)
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):
name = tables.Column(
linkify=True
)
group = tables.Column(
linkify=True
)
comments = columns.MarkdownColumn()
tags = columns.TagColumn(
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):
name = columns.MPTTColumn(
2021-10-18 11:45:05 -04:00
linkify=True
)
contact_count = columns.LinkedCountColumn(
2021-10-18 11:45:05 -04:00
viewname='tenancy:contact_list',
url_params={'role_id': 'pk'},
verbose_name='Contacts'
)
tags = columns.TagColumn(
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',
)
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')
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
)
phone = tables.Column(
linkify=linkify_phone,
)
comments = columns.MarkdownColumn()
2021-10-18 15:30:28 -04:00
assignment_count = tables.Column(
verbose_name='Assignments'
)
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):
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
)
actions = columns.ActionsColumn(
sequence=('edit', 'delete')
)
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
fields = ('pk', 'content_type', 'object', 'contact', 'role', 'priority', 'actions')
default_columns = ('pk', 'content_type', 'object', 'contact', 'role', 'priority')