Added dashboard column to display data-type of typed contents
authorThierry Florac <tflorac@ulthar.net>
Fri, 04 Jan 2019 17:10:04 +0100
changeset 1209 fcc1cf94976c
parent 1208 0ec8963e088e
child 1210 2c35b6b0486c
Added dashboard column to display data-type of typed contents
src/pyams_content/shared/common/zmi/dashboard.py
--- a/src/pyams_content/shared/common/zmi/dashboard.py	Fri Jan 04 12:20:34 2019 +0100
+++ b/src/pyams_content/shared/common/zmi/dashboard.py	Fri Jan 04 17:10:04 2019 +0100
@@ -9,6 +9,8 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.shared.common.interfaces.types import IWfTypedSharedContent
+
 
 __docformat__ = 'restructuredtext'
 
@@ -97,6 +99,23 @@
         return tuple(super(BaseDashboardTable, self).values)
 
 
+@adapter_config(name='type', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn)
+class SharedToolDashboardTypeColumn(I18nColumn, GetAttrColumn):
+    """Shared tool dashboard type column"""
+
+    _header = _("Type")
+    weight = 9
+
+    def getValue(self, obj):
+        content = IWfTypedSharedContent(obj, None)
+        if content is not None:
+            data_type = content.get_data_type()
+            if data_type is not None:
+                return II18n(data_type).query_attribute('navigation_label', request=self.request) or \
+                       II18n(data_type).query_attribute('label', request=self.request)
+        return '--'
+
+
 @adapter_config(name='name', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn)
 class SharedToolDashboardNameColumn(NameColumn):
     """Shared tool dashboard name column"""