Added column to get I18n attribute value
authorThierry Florac <thierry.florac@onf.fr>
Tue, 16 May 2017 11:12:12 +0200
changeset 27 18ef849f6cda
parent 26 b32a12468785
child 28 16c82cc767a3
Added column to get I18n attribute value
src/pyams_i18n/column.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_i18n/column.py	Tue May 16 11:12:12 2017 +0200
@@ -0,0 +1,31 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_i18n.interfaces import II18n
+
+# import packages
+from z3c.table.column import GetAttrColumn
+
+
+class I18nAttrColumn(GetAttrColumn):
+    """Column with I18n attribute 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