tables.py 883 B

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