Updated associations interface to add user icon
authorThierry Florac <tflorac@ulthar.net>
Thu, 08 Feb 2018 17:21:30 +0100
changeset 384 d433c8c46ec9
parent 383 8409f13da5d0
child 385 6310e9a80209
Updated associations interface to add user icon
src/pyams_content/component/association/interfaces/__init__.py
src/pyams_content/component/association/zmi/__init__.py
src/pyams_content/component/extfile/__init__.py
src/pyams_content/component/links/__init__.py
--- a/src/pyams_content/component/association/interfaces/__init__.py	Thu Feb 08 15:51:58 2018 +0100
+++ b/src/pyams_content/component/association/interfaces/__init__.py	Thu Feb 08 17:21:30 2018 +0100
@@ -55,6 +55,8 @@
 
     user_title = Attribute("Association title proposed on public site")
 
+    user_icon = Attribute("Iocn associated with user title")
+
     inner_title = Attribute("Inner content, if available")
 
     human_size = Attribute("Content size, if available")
--- a/src/pyams_content/component/association/zmi/__init__.py	Thu Feb 08 15:51:58 2018 +0100
+++ b/src/pyams_content/component/association/zmi/__init__.py	Thu Feb 08 17:21:30 2018 +0100
@@ -230,9 +230,12 @@
     def getValue(self, obj):
         info = IAssociationInfo(obj, None)
         if info is not None:
-            return info.user_title
+            title = info.user_title
         else:
-            return '--'
+            title = '--'
+        if info.user_icon:
+            title += ' ' + info.user_icon
+        return title
 
 
 @adapter_config(name='inner_name', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn)
--- a/src/pyams_content/component/extfile/__init__.py	Thu Feb 08 15:51:58 2018 +0100
+++ b/src/pyams_content/component/extfile/__init__.py	Thu Feb 08 17:21:30 2018 +0100
@@ -87,15 +87,19 @@
 
     @property
     def user_title(self):
+        title = II18n(self.context).query_attribute('title')
+        if not title:
+            title = self.context.filename
+        return title
+
+    @property
+    def user_icon(self):
         filename = self.context.filename
         if filename:
             name, ext = os.path.splitext(filename)
-            return '{title} <img class="margin-left-5 align-top" ' \
+            return '<img class="margin-left-5 align-top" ' \
                 'src="/--static--/pyams_skin/img/mimetypes/16x16/{thumb}" />'.format(
-                 title=II18n(self.context).query_attribute('title') or filename,
                  thumb=EXTENSIONS_THUMBNAILS.get(ext, 'unknown.png'))
-        else:
-            return '--'
 
     @property
     def inner_title(self):
--- a/src/pyams_content/component/links/__init__.py	Thu Feb 08 15:51:58 2018 +0100
+++ b/src/pyams_content/component/links/__init__.py	Thu Feb 08 17:21:30 2018 +0100
@@ -77,6 +77,8 @@
     def pictogram(self):
         return self.context.icon_class
 
+    user_icon = None
+
 
 class BaseLinkContentChecker(BaseContentChecker):
     """Base link content checker"""