2016-07-26 14:58:37 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
2020-09-25 12:42:17 -04:00
|
|
|
from utilities.tables import BaseTable, ButtonsColumn, LinkedCountColumn, TagColumn, ToggleColumn
|
2016-07-26 14:58:37 -04:00
|
|
|
from .models import Tenant, TenantGroup
|
|
|
|
|
2020-03-11 20:20:04 -04:00
|
|
|
MPTT_LINK = """
|
2020-12-22 16:14:16 -05:00
|
|
|
{% for i in record.get_ancestors %}
|
|
|
|
<i class="mdi mdi-circle-small"></i>
|
|
|
|
{% endfor %}
|
|
|
|
<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
|
2020-03-11 20:20:04 -04:00
|
|
|
"""
|
|
|
|
|
2018-01-30 11:57:21 -05:00
|
|
|
COL_TENANT = """
|
|
|
|
{% if record.tenant %}
|
|
|
|
<a href="{% url 'tenancy:tenant' slug=record.tenant.slug %}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
|
|
|
|
{% else %}
|
|
|
|
—
|
|
|
|
{% endif %}
|
|
|
|
"""
|
|
|
|
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Tenant groups
|
|
|
|
#
|
|
|
|
|
|
|
|
class TenantGroupTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2020-03-11 20:20:04 -04:00
|
|
|
name = tables.TemplateColumn(
|
|
|
|
template_code=MPTT_LINK,
|
2020-12-30 15:30:31 -05:00
|
|
|
orderable=False,
|
|
|
|
attrs={'td': {'class': 'text-nowrap'}}
|
2020-03-11 20:20:04 -04:00
|
|
|
)
|
2020-09-25 12:42:17 -04:00
|
|
|
tenant_count = LinkedCountColumn(
|
|
|
|
viewname='tenancy:tenant_list',
|
|
|
|
url_params={'group': 'slug'},
|
2020-03-11 20:20:04 -04:00
|
|
|
verbose_name='Tenants'
|
|
|
|
)
|
2020-07-01 13:47:01 -04:00
|
|
|
actions = ButtonsColumn(TenantGroup, pk_field='slug')
|
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()
|
2017-03-29 16:05:23 -04:00
|
|
|
name = tables.LinkColumn()
|
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')
|