tables.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import django_tables2 as tables
  2. from django.utils.safestring import mark_safe
  3. class BaseTable(tables.Table):
  4. """
  5. Default table for object lists
  6. """
  7. def __init__(self, *args, **kwargs):
  8. super(BaseTable, self).__init__(*args, **kwargs)
  9. # Set default empty_text if none was provided
  10. if self.empty_text is None:
  11. self.empty_text = 'No {} found.'.format(self._meta.model._meta.verbose_name_plural)
  12. class Meta:
  13. attrs = {
  14. 'class': 'table table-hover',
  15. }
  16. class SearchTable(tables.Table):
  17. """
  18. Default table for search results
  19. """
  20. class Meta:
  21. attrs = {
  22. 'class': 'table table-hover table-headings',
  23. }
  24. orderable = False
  25. class ToggleColumn(tables.CheckBoxColumn):
  26. def __init__(self, *args, **kwargs):
  27. default = kwargs.pop('default', '')
  28. visible = kwargs.pop('visible', False)
  29. super(ToggleColumn, self).__init__(*args, default=default, visible=visible, **kwargs)
  30. @property
  31. def header(self):
  32. return mark_safe('<input type="checkbox" id="toggle_all" title="Toggle all" />')