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

Move custom columns to util namespace

parent 0c10a5b5
No related branches found
No related tags found
1 merge request!502Add support to build tables and forms for executing actions for multiple objects
Pipeline #6407 passed
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, AttributeDict, computed_values
from django_tables2.utils import A
class SchoolTermTable(tables.Table):
......@@ -92,45 +91,3 @@ class DashboardWidgetTable(tables.Table):
def render_widget_name(self, value, record):
return record._meta.verbose_name
class MaterializeCheckboxColumn(tables.CheckBoxColumn):
"""Checkbox column with Materialize support."""
empty_values = ()
@property
def header(self):
"""Render the header cell."""
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):
"""Render a data cell."""
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()
)
class SelectColumn(MaterializeCheckboxColumn):
"""Column with a check box prepared for `ActionForm` forms."""
def __init__(self, *args, **kwargs):
kwargs["attrs"] = {
"td__input": {"name": "selected_objects"},
"th__input": {"id": "header_box"},
}
kwargs.setdefault("accessor", A("pk"))
super().__init__(*args, **kwargs)
from django.utils.safestring import mark_safe
from django_tables2 import CheckBoxColumn
from django_tables2.utils import A, AttributeDict, computed_values
class MaterializeCheckboxColumn(CheckBoxColumn):
"""Checkbox column with Materialize support."""
empty_values = ()
@property
def header(self):
"""Render the header cell."""
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):
"""Render a data cell."""
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()
)
class SelectColumn(MaterializeCheckboxColumn):
"""Column with a check box prepared for `ActionForm` forms."""
def __init__(self, *args, **kwargs):
kwargs["attrs"] = {
"td__input": {"name": "selected_objects"},
"th__input": {"id": "header_box"},
}
kwargs.setdefault("accessor", A("pk"))
super().__init__(*args, **kwargs)
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