Added default container values adapter
authorThierry Florac <thierry.florac@onf.fr>
Wed, 20 May 2015 12:34:50 +0200
changeset 63 5c27fa323eff
parent 62 95b8b181c3ad
child 64 3fe1d315747c
Added default container values adapter
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Wed May 20 12:34:23 2015 +0200
+++ b/src/pyams_skin/table.py	Wed May 20 12:34:50 2015 +0200
@@ -19,8 +19,8 @@
 from pyams_skin.interfaces.container import ITable, ITableElementEditor, ITableWithActions, ITableElementName
 from pyams_skin.layer import IPyAMSLayer
 from pyams_viewlet.interfaces import IViewletManager
-from z3c.table.interfaces import IColumn
-from zope.container.interfaces import IContained
+from z3c.table.interfaces import IColumn, IValues
+from zope.container.interfaces import IContained, IContainer
 
 # import packages
 from pyams_template.template import get_view_template, template_config
@@ -87,9 +87,7 @@
 
     @staticmethod
     def check_data_attribute(attribute, source):
-        if isinstance(attribute, str):
-            return attribute
-        elif callable(attribute):
+        if callable(attribute):
             return attribute(source)
         else:
             return str(attribute)
@@ -121,6 +119,15 @@
                                      .replace('<td', '<td %s' % self.get_data_attributes('td', item, column))
 
 
+@adapter_config(context=(IContainer, IPyAMSLayer, BaseTable), provides=IValues)
+class ContainerValuesAdapter(ContextRequestViewAdapter):
+    """Default container values adapter"""
+
+    @property
+    def values(self):
+        return list(self.context.values())
+
+
 class I18nColumn(object):
     """Column with I18n header column"""