Added thumbnails for external files
authortflorac@xsup98-004.onf.fr
Thu, 12 Oct 2017 22:27:18 +0200
changeset 201 46819098e77a
parent 200 af969d925a91
child 202 7d7947f69fce
Added thumbnails for external files
src/pyams_content/component/extfile/__init__.py
--- a/src/pyams_content/component/extfile/__init__.py	Thu Oct 12 22:26:26 2017 +0200
+++ b/src/pyams_content/component/extfile/__init__.py	Thu Oct 12 22:27:18 2017 +0200
@@ -14,6 +14,7 @@
 
 
 # import standard library
+import os
 
 # import interfaces
 from pyams_content.component.association.interfaces import IAssociationInfo
@@ -27,6 +28,7 @@
 
 # import packages
 from pyams_content.component.association import AssociationItem
+from pyams_file.file import ImageFile, VideoFile, AudioFile, EXTENSIONS_THUMBNAILS
 from pyams_i18n.property import I18nFileProperty
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.registry import query_utility
@@ -84,7 +86,11 @@
 
     @property
     def user_title(self):
-        return II18n(self.context).query_attribute('title') or self.context.filename
+        name, ext = os.path.splitext(self.context.filename)
+        return '{title} <img class="margin-left-5 align-top" ' \
+               'src="/--static--/pyams_skin/img/mimetypes/16x16/{thumb}" />'.format(
+            title=II18n(self.context).query_attribute('title') or self.context.filename,
+            thumb=EXTENSIONS_THUMBNAILS.get(ext, 'unknown.png'))
 
     @property
     def inner_title(self):
@@ -124,9 +130,7 @@
                 extfile.filename = info.filename
             else:
                 info.filename = extfile.filename
-        for lang, data in (extfile.data or {}).items():
-            if data is not None:
-                IFileInfo(data).language = lang
+            info.language = extfile.language
 
 
 @subscriber(IObjectAddedEvent, context_selector=IBaseExtFile)
@@ -165,7 +169,7 @@
 class ExtFile(BaseExtFile):
     """Generic external file persistent class"""
 
-    icon_class = 'fa-file-o'
+    icon_class = 'fa-file-text-o'
     icon_hint = _("Standard file")
 
     data = I18nFileProperty(IExtFile['data'])