2016-07-26 14:58:37 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
2021-03-04 20:47:24 -05:00
|
|
|
from utilities.tables import BaseTable, ButtonsColumn, LinkedCountColumn, MPTTColumn, TagColumn, ToggleColumn
|
2016-07-26 14:58:37 -04:00
|
|
|
from .models import Tenant, TenantGroup
|
|
|
|
|
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
|
|
|
|
|
|
|
#
|
|
|
|
# Tenant groups
|
|
|
|
#
|
|
|
|
|
|
|
|
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-02-26 17:23:23 -05:00
|
|
|
actions = ButtonsColumn(TenantGroup)
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = TenantGroup
|
2020-03-13 16:24:37 -04:00
|
|
|
fields = ('pk', 'name', 'tenant_count', 'description', 'slug', '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
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tenants
|
|
|
|
#
|
|
|
|
|
|
|
|
class TenantTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
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
|
2020-05-06 14:42:51 -04:00
|
|
|
fields = ('pk', 'name', 'slug', 'group', 'description', 'tags')
|
2020-04-29 11:34:51 -04:00
|
|
|
default_columns = ('pk', 'name', 'group', 'description')
|