Updated user title display
authorThierry Florac <thierry.florac@onf.fr>
Tue, 23 Oct 2018 17:24:41 +0200
changeset 1034 87f03e244266
parent 1033 6ca1041099d3
child 1035 857fdb137d14
Updated user title display
src/pyams_content/component/extfile/__init__.py
--- a/src/pyams_content/component/extfile/__init__.py	Tue Oct 23 15:51:01 2018 +0200
+++ b/src/pyams_content/component/extfile/__init__.py	Tue Oct 23 17:24:41 2018 +0200
@@ -12,37 +12,33 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
 import os
 
-# import interfaces
-from pyams_content.component.association.interfaces import IAssociationInfo
-from pyams_content.component.extfile.interfaces import IBaseExtFile, IExtFile, IExtImage, IExtVideo, IExtAudio, \
-    IExtMedia
-from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
-from pyams_content.shared.common.interfaces import IWfSharedContent
-from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage
-from pyams_i18n.interfaces import II18n, INegotiator, II18nManager
+from pyramid.events import subscriber
+from pyramid.threadlocal import get_current_registry
+from zope.interface import alsoProvides, implementer
+from zope.lifecycleevent import ObjectModifiedEvent
 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
+from zope.schema.fieldproperty import FieldProperty
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
-# import packages
 from pyams_content.component.association import AssociationItem
+from pyams_content.component.association.interfaces import IAssociationInfo
+from pyams_content.component.extfile.interfaces import IBaseExtFile, IExtAudio, IExtFile, IExtFileManagerInfo, \
+    IExtImage, IExtMedia, IExtVideo
 from pyams_content.features.checker import BaseContentChecker
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
+from pyams_content.shared.common.interfaces import IWfSharedContent
 from pyams_file.file import EXTENSIONS_THUMBNAILS
+from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage
+from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
 from pyams_i18n.property import I18nFileProperty
-from pyams_utils.adapter import adapter_config, ContextAdapter
-from pyams_utils.registry import query_utility, get_utility
+from pyams_utils.adapter import ContextAdapter, adapter_config
+from pyams_utils.registry import get_utility, query_utility
 from pyams_utils.request import check_request
 from pyams_utils.size import get_human_size
 from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
-from pyramid.events import subscriber
-from pyramid.threadlocal import get_current_registry
-from zope.interface import implementer, alsoProvides
-from zope.lifecycleevent import ObjectModifiedEvent
-from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_content import _
 
@@ -87,10 +83,13 @@
 
     @property
     def user_title(self):
+        request = check_request()
+        manager_info = IExtFileManagerInfo(request.root)
         title = II18n(self.context).query_attribute('title')
         if not title:
             title = self.context.filename
-        return title
+        return '{0} {1}'.format(II18n(manager_info).query_attribute('default_title_prefix', request=request) or '',
+                                title)
 
     @property
     def user_icon(self):
@@ -173,6 +172,7 @@
 
     data = I18nFileProperty(IExtFile['data'])
 
+
 register_file_factory('file', ExtFile, _("Standard file"))
 
 
@@ -185,7 +185,7 @@
         request = check_request()
         translate = request.localizer.translate
         return II18n(self.context).query_attribute('title', request) or \
-            '({0})'.format(translate(self.context.icon_hint).lower())
+               '({0})'.format(translate(self.context.icon_hint).lower())
 
     interface = IExtFile
 
@@ -197,7 +197,7 @@
             langs = manager.get_languages()
         else:
             negotiator = get_utility(INegotiator)
-            langs = (negotiator.server_language, )
+            langs = (negotiator.server_language,)
         i18n = II18n(self.context)
         for attr in ('title', 'data'):
             for lang in langs:
@@ -235,6 +235,7 @@
             if IImage.providedBy(data):
                 alsoProvides(data, IResponsiveImage)
 
+
 register_file_factory('image', ExtImage, _("Image"))
 
 
@@ -254,6 +255,7 @@
 
     data = I18nFileProperty(IExtVideo['data'])
 
+
 register_file_factory('video', ExtVideo, _("Video"))
 
 
@@ -273,6 +275,7 @@
 
     data = I18nFileProperty(IExtAudio['data'])
 
+
 register_file_factory('audio', ExtAudio, _("Audio file"))