2016-07-26 14:58:37 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
2020-05-06 14:42:51 -04:00
|
|
|
from utilities.tables import BaseTable, 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 = """
|
|
|
|
{% if record.get_children %}
|
|
|
|
<span style="padding-left: {{ record.get_ancestors|length }}0px "><i class="fa fa-caret-right"></i>
|
|
|
|
{% else %}
|
|
|
|
<span style="padding-left: {{ record.get_ancestors|length }}9px">
|
|
|
|
{% endif %}
|
|
|
|
<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
|
2016-07-28 16:03:59 -04:00
|
|
|
TENANTGROUP_ACTIONS = """
|
2020-02-19 12:45:52 -05:00
|
|
|
<a href="{% url 'tenancy:tenantgroup_changelog' slug=record.slug %}" class="btn btn-default btn-xs" title="Change log">
|
2018-06-20 14:54:04 -04:00
|
|
|
<i class="fa fa-history"></i>
|
|
|
|
</a>
|
2016-07-26 14:58:37 -04:00
|
|
|
{% if perms.tenancy.change_tenantgroup %}
|
2019-04-08 14:10:55 -04:00
|
|
|
<a href="{% url 'tenancy:tenantgroup_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
|
2016-07-26 14:58:37 -04:00
|
|
|
{% endif %}
|
|
|
|
"""
|
|
|
|
|
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,
|
|
|
|
orderable=False
|
|
|
|
)
|
|
|
|
tenant_count = tables.Column(
|
|
|
|
verbose_name='Tenants'
|
|
|
|
)
|
2017-05-24 11:33:11 -04:00
|
|
|
actions = tables.TemplateColumn(
|
2020-03-11 20:20:04 -04:00
|
|
|
template_code=TENANTGROUP_ACTIONS,
|
|
|
|
attrs={'td': {'class': 'text-right noprint'}},
|
|
|
|
verbose_name=''
|
2017-05-24 11:33:11 -04:00
|
|
|
)
|
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')
|