tables.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from __future__ import unicode_literals
  2. import django_tables2 as tables
  3. from utilities.tables import BaseTable, ToggleColumn
  4. from .models import Tenant, TenantGroup
  5. TENANTGROUP_ACTIONS = """
  6. {% if perms.tenancy.change_tenantgroup %}
  7. <a href="{% url 'tenancy:tenantgroup_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
  8. {% endif %}
  9. """
  10. COL_TENANT = """
  11. {% if record.tenant %}
  12. <a href="{% url 'tenancy:tenant' slug=record.tenant.slug %}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
  13. {% else %}
  14. &mdash;
  15. {% endif %}
  16. """
  17. #
  18. # Tenant groups
  19. #
  20. class TenantGroupTable(BaseTable):
  21. pk = ToggleColumn()
  22. name = tables.LinkColumn(verbose_name='Name')
  23. tenant_count = tables.Column(verbose_name='Tenants')
  24. slug = tables.Column(verbose_name='Slug')
  25. actions = tables.TemplateColumn(
  26. template_code=TENANTGROUP_ACTIONS, attrs={'td': {'class': 'text-right'}}, verbose_name=''
  27. )
  28. class Meta(BaseTable.Meta):
  29. model = TenantGroup
  30. fields = ('pk', 'name', 'tenant_count', 'slug', 'actions')
  31. #
  32. # Tenants
  33. #
  34. class TenantTable(BaseTable):
  35. pk = ToggleColumn()
  36. name = tables.LinkColumn()
  37. class Meta(BaseTable.Meta):
  38. model = Tenant
  39. fields = ('pk', 'name', 'group', 'description')