tables.py 989 B

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