Added shared content title prefix adapter
authorThierry Florac <thierry.florac@onf.fr>
Thu, 12 May 2016 10:49:09 +0200
changeset 30 dd345161e0b6
parent 29 e070eeac5530
child 31 0505d35a472d
Added shared content title prefix adapter
src/pyams_content/shared/common/zmi/header.py
--- a/src/pyams_content/shared/common/zmi/header.py	Wed May 11 12:24:59 2016 +0200
+++ b/src/pyams_content/shared/common/zmi/header.py	Thu May 12 10:49:09 2016 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_content.profile.interfaces import IAdminProfile
 
 __docformat__ = 'restructuredtext'
 
@@ -17,16 +16,20 @@
 # import standard library
 
 # import interfaces
+from pyams_content.profile.interfaces import IAdminProfile
 from pyams_content.shared.common.interfaces import IWfSharedContent, ISharedTool
 from pyams_form.interfaces.form import IInnerTabForm
 from pyams_i18n.interfaces import II18n
 from pyams_security.interfaces import ISecurityManager
 from pyams_sequence.interfaces import ISequentialIntIds, ISequentialIdInfo
+from pyams_skin.interfaces import IContextTitlePrefix
 from pyams_skin.layer import IPyAMSLayer
 from pyams_workflow.interfaces import IWorkflowState, IWorkflow, IWorkflowStateLabel, IWorkflowVersions
 
 # import packages
+from pyams_skin.site import ContextTitlePrefixAdapter
 from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
 from pyams_utils.date import format_datetime
 from pyams_utils.registry import get_utility
 from pyams_utils.traversing import get_parent
@@ -38,6 +41,20 @@
 from pyams_content import _
 
 
+@adapter_config(context=(IWfSharedContent, IPyAMSLayer), provides=IContextTitlePrefix)
+class SharedContentTitlePrefixAdapter(ContextTitlePrefixAdapter):
+    """Shared content title prefix adapter"""
+
+    @property
+    def prefix(self):
+        result = super(SharedContentTitlePrefixAdapter, self).prefix
+        title = II18n(self.context).query_attribute('short_name', request=self.request)
+        if result and title:
+            return '{result} > {title}'.format(**locals())
+        else:
+            return result or title
+
+
 @contentprovider_config(name='content_header', context=IWfSharedContent, view=Interface, layer=IPyAMSLayer)
 @template_config(template='templates/header.pt', layer=IPyAMSLayer)
 class SharedContentHeaderContentProvider(object):