Skip to content
Snippets Groups Projects
Verified Commit df3e032a authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add MaterializeCheckboxColumn for django-tables2 with Materialize support

parent cf471364
No related branches found
No related tags found
1 merge request!502Add support to build tables and forms for executing actions for multiple objects
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
import django_tables2 as tables
from django_tables2.utils import A
from django_tables2.utils import A, AttributeDict, computed_values
class SchoolTermTable(tables.Table):
......@@ -91,3 +92,29 @@ class DashboardWidgetTable(tables.Table):
def render_widget_name(self, value, record):
return record._meta.verbose_name
class MaterializeCheckboxColumn(tables.CheckBoxColumn):
empty_values = ()
@property
def header(self):
default = {"type": "checkbox"}
general = self.attrs.get("input")
specific = self.attrs.get("th__input")
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe("<label><input %s/><span></span></label>" % attrs.as_html()) # noqa
def render(self, value, bound_column, record):
default = {"type": "checkbox", "name": bound_column.name, "value": value}
if self.is_checked(value, record):
default.update({"checked": "checked"})
general = self.attrs.get("input")
specific = self.attrs.get("td__input")
attrs = dict(default, **(specific or general or {}))
attrs = computed_values(attrs, kwargs={"record": record, "value": value})
return mark_safe( # noqa
"<label><input %s/><span></span</label>" % AttributeDict(attrs).as_html()
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment