Added I18n value column
authorThierry Florac <thierry.florac@onf.fr>
Tue, 19 Sep 2017 11:15:38 +0200
changeset 206 7ac7101a76c6
parent 205 538a8adb6d73
child 207 afe6800e94ec
Added I18n value column
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Wed Sep 13 15:54:54 2017 +0200
+++ b/src/pyams_skin/table.py	Tue Sep 19 11:15:38 2017 +0200
@@ -16,6 +16,7 @@
 # import standard library
 
 # import interfaces
+from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces.container import ITable, ITableElementEditor, ITableWithActions, ITableElementName
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import MANAGE_PERMISSION
@@ -156,6 +157,15 @@
         return self.request.localizer.translate(self._header)
 
 
+class I18nValueColumn(GetAttrColumn):
+    """Column with I18n value"""
+
+    def getValue(self, obj):
+        if obj is not None and self.attrName is not None:
+            return II18n(obj).query_attribute(self.attrName, request=self.request)
+        return self.defaultValue
+
+
 @adapter_config(name='name', context=(Interface, IPyAMSLayer, BaseTable), provides=IColumn)
 class NameColumn(I18nColumn, GetAttrColumn):
     """Container name column"""