2016-07-26 14:58:37 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
2021-09-17 12:04:22 -04:00
|
|
|
from utilities.tables import (
|
2021-12-03 10:51:24 -05:00
|
|
|
BaseTable, ButtonsColumn, ContentTypeColumn, LinkedCountColumn, linkify_phone, MarkdownColumn, MPTTColumn,
|
|
|
|
TagColumn, ToggleColumn,
|
2021-09-17 12:04:22 -04:00
|
|
|
)
|
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
|
|
|
#
|
|
|
|
|
|
|
|
class TenantGroupTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2021-03-26 15:07:29 -04:00
|
|
|
name = MPTTColumn(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-09-25 12:42:17 -04:00
|
|
|
tenant_count = LinkedCountColumn(
|
|
|
|
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'
|
|
|
|
)
|
2021-10-21 10:51:02 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='tenancy:tenantgroup_list'
|
|
|
|
)
|
2021-02-26 17:23:23 -05:00
|
|
|
actions = ButtonsColumn(TenantGroup)
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = TenantGroup
|
2021-11-03 10:29:02 -04:00
|
|
|
fields = ('pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'actions')
|
2020-04-29 11:34:51 -04:00
|
|
|
default_columns = ('pk', 'name', 'tenant_count', 'description', 'actions')
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TenantTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
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
|
|
|
|
)
|
2021-09-17 12:04:22 -04:00
|
|
|
comments = MarkdownColumn()
|
2020-05-06 14:42:51 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='tenancy:tenant_list'
|
|
|
|
)
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = Tenant
|
2021-11-02 16:21:34 -04:00
|
|
|
fields = ('pk', 'id', 'name', 'slug', 'group', 'description', 'comments', 'tags')
|
2020-04-29 11:34:51 -04:00
|
|
|
default_columns = ('pk', 'name', 'group', 'description')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Contacts
|
|
|
|
#
|
|
|
|
|
|
|
|
class ContactGroupTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = MPTTColumn(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
contact_count = LinkedCountColumn(
|
|
|
|
viewname='tenancy:contact_list',
|
|
|
|
url_params={'role_id': 'pk'},
|
|
|
|
verbose_name='Contacts'
|
|
|
|
)
|
2021-10-21 10:51:02 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='tenancy:contactgroup_list'
|
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
actions = ButtonsColumn(ContactGroup)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ContactGroup
|
2021-10-21 10:51:02 -04:00
|
|
|
fields = ('pk', 'name', 'contact_count', 'description', 'slug', 'tags', 'actions')
|
2021-10-18 11:45:05 -04:00
|
|
|
default_columns = ('pk', 'name', 'contact_count', 'description', 'actions')
|
|
|
|
|
|
|
|
|
|
|
|
class ContactRoleTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
actions = ButtonsColumn(ContactRole)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ContactRole
|
|
|
|
fields = ('pk', 'name', 'description', 'slug', 'actions')
|
|
|
|
default_columns = ('pk', 'name', 'description', 'actions')
|
|
|
|
|
|
|
|
|
|
|
|
class ContactTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
group = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-12-03 10:51:24 -05:00
|
|
|
phone = tables.Column(
|
|
|
|
linkify=linkify_phone,
|
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
comments = MarkdownColumn()
|
2021-10-18 15:30:28 -04:00
|
|
|
assignment_count = tables.Column(
|
|
|
|
verbose_name='Assignments'
|
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='tenancy:tenant_list'
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = Contact
|
2021-10-18 15:30:28 -04:00
|
|
|
fields = ('pk', 'name', 'group', 'title', 'phone', 'email', 'address', 'comments', 'assignment_count', 'tags')
|
|
|
|
default_columns = ('pk', 'name', 'group', 'assignment_count', 'title', 'phone', 'email')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ContactAssignmentTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2021-10-18 15:30:28 -04:00
|
|
|
content_type = ContentTypeColumn(
|
|
|
|
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
|
|
|
|
)
|
2021-11-04 14:01:07 -04:00
|
|
|
actions = ButtonsColumn(
|
|
|
|
model=ContactAssignment,
|
|
|
|
buttons=('edit', 'delete')
|
|
|
|
)
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ContactAssignment
|
2021-11-04 14:01:07 -04:00
|
|
|
fields = ('pk', 'content_type', 'object', 'contact', 'role', 'priority', 'actions')
|
|
|
|
default_columns = ('pk', 'content_type', 'object', 'contact', 'role', 'priority', 'actions')
|