2
0

tables.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import django_tables2 as tables
  2. from utilities.tables import BaseTable, ButtonsColumn, LinkedCountColumn, TagColumn, ToggleColumn
  3. from .models import Tenant, TenantGroup
  4. MPTT_LINK = """
  5. {% for i in record.get_ancestors %}
  6. <i class="mdi mdi-circle-small"></i>
  7. {% endfor %}
  8. <a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
  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.TemplateColumn(
  23. template_code=MPTT_LINK,
  24. orderable=False
  25. )
  26. tenant_count = LinkedCountColumn(
  27. viewname='tenancy:tenant_list',
  28. url_params={'group': 'slug'},
  29. verbose_name='Tenants'
  30. )
  31. actions = ButtonsColumn(TenantGroup, pk_field='slug')
  32. class Meta(BaseTable.Meta):
  33. model = TenantGroup
  34. fields = ('pk', 'name', 'tenant_count', 'description', 'slug', 'actions')
  35. default_columns = ('pk', 'name', 'tenant_count', 'description', 'actions')
  36. #
  37. # Tenants
  38. #
  39. class TenantTable(BaseTable):
  40. pk = ToggleColumn()
  41. name = tables.LinkColumn()
  42. tags = TagColumn(
  43. url_name='tenancy:tenant_list'
  44. )
  45. class Meta(BaseTable.Meta):
  46. model = Tenant
  47. fields = ('pk', 'name', 'slug', 'group', 'description', 'tags')
  48. default_columns = ('pk', 'name', 'group', 'description')