From ad1ab72761d8ca060e2064d2fd4bed8bc2b2ac53 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sun, 14 Mar 2021 16:46:25 +0100
Subject: [PATCH] Move custom columns to util namespace

---
 aleksis/core/tables.py      | 45 +-----------------------------------
 aleksis/core/util/tables.py | 46 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 44 deletions(-)
 create mode 100644 aleksis/core/util/tables.py

diff --git a/aleksis/core/tables.py b/aleksis/core/tables.py
index ccf9c61a6..54d3f3e5c 100644
--- a/aleksis/core/tables.py
+++ b/aleksis/core/tables.py
@@ -1,8 +1,7 @@
-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)
diff --git a/aleksis/core/util/tables.py b/aleksis/core/util/tables.py
new file mode 100644
index 000000000..50a27a52b
--- /dev/null
+++ b/aleksis/core/util/tables.py
@@ -0,0 +1,46 @@
+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)
-- 
GitLab