diff --git a/modoboa/lib/tables.py b/modoboa/lib/tables.py
index 1ba254f49..82920a8bb 100644
--- a/modoboa/lib/tables.py
+++ b/modoboa/lib/tables.py
@@ -16,7 +16,7 @@ from django.template import Template, RequestContext, Context
from django.template.loader import render_to_string
from templatetags.libextras import render_link
-class Column:
+class Column(object):
"""Simple column representation
"""
def __init__(self, name, **kwargs):
@@ -32,6 +32,25 @@ class Column:
label = getattr(self, "name")
return label.encode("utf-8")
+ def transform(self, row, col, table):
+ if "class" in row.keys():
+ col["cssclass"] += col["cssclass"] != "" \
+ and ", %s" % row["class"] or row["class"]
+ try:
+ col["value"] = table.parse(self.name, row[self.name])
+ except AttributeError:
+ col["value"] = row[self.name]
+ try:
+ limit = getattr(self, "limit")
+ if len(col["value"]) > limit:
+ col["value"] = col["value"][0:limit] + "..."
+ except AttributeError:
+ pass
+ try:
+ col["safe"] = getattr(self, "safe")
+ except AttributeError:
+ pass
+
class SelectionColumn(Column):
"""Specific column: selection
@@ -47,6 +66,11 @@ class SelectionColumn(Column):
return "" \
% (self.name, value, value, selection and "checked" or "")
+ def transform(self, row, col, table):
+ selection = row.has_key(self.name) and row[self.name] or False
+ col["value"] = self.render(row[table.idkey], selection)
+ col["safe"] = True
+
class ImgColumn(Column):
"""Specific column: image
@@ -64,6 +88,17 @@ class ImgColumn(Column):
return "".join(map(lambda i: "" % i, value))
return "
" % value
+ def transform(self, row, col, table):
+ key = "img_%s" % self.name
+ if key in row.keys():
+ col["value"] = self.render(row[key])
+ else:
+ try:
+ col["value"] = self.render(self.defvalue)
+ except Exception:
+ pass
+ col["safe"] = True
+
class DivColumn(Column):
def __str__(self):
return ""
@@ -71,10 +106,18 @@ class DivColumn(Column):
def render(self):
return "