tables.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import django_tables2 as tables
  2. from utilities.tables import BaseTable, ButtonsColumn, LinkedCountColumn, TagColumn, ToggleColumn
  3. from .models import SecretRole, Secret
  4. #
  5. # Secret roles
  6. #
  7. class SecretRoleTable(BaseTable):
  8. pk = ToggleColumn()
  9. name = tables.Column(
  10. linkify=True
  11. )
  12. secret_count = LinkedCountColumn(
  13. viewname='secrets:secret_list',
  14. url_params={'role_id': 'pk'},
  15. verbose_name='Secrets'
  16. )
  17. actions = ButtonsColumn(SecretRole)
  18. class Meta(BaseTable.Meta):
  19. model = SecretRole
  20. fields = ('pk', 'name', 'secret_count', 'description', 'slug', 'actions')
  21. default_columns = ('pk', 'name', 'secret_count', 'description', 'actions')
  22. #
  23. # Secrets
  24. #
  25. class SecretTable(BaseTable):
  26. pk = ToggleColumn()
  27. id = tables.Column( # Provides a link to the secret
  28. linkify=True
  29. )
  30. assigned_object = tables.Column(
  31. linkify=True,
  32. verbose_name='Assigned object'
  33. )
  34. role = tables.Column(
  35. linkify=True
  36. )
  37. tags = TagColumn(
  38. url_name='secrets:secret_list'
  39. )
  40. class Meta(BaseTable.Meta):
  41. model = Secret
  42. fields = ('pk', 'id', 'assigned_object', 'role', 'name', 'last_updated', 'hash', 'tags')
  43. default_columns = ('pk', 'id', 'assigned_object', 'role', 'name', 'last_updated')