Added default context title prefix adapter
authorThierry Florac <thierry.florac@onf.fr>
Thu, 12 May 2016 11:00:58 +0200
changeset 137 2dec7379f935
parent 136 cdad4eadfd43
child 138 4ce6e8538a8d
Added default context title prefix adapter
src/pyams_skin/site.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_skin/site.py	Thu May 12 11:00:58 2016 +0200
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_skin.interfaces import IContextTitlePrefix
+from pyams_skin.interfaces.configuration import IBackOfficeConfiguration
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces.site import ISiteRoot
+
+# import packages
+from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.traversing import get_parent
+from zope.interface import Interface
+
+
+@adapter_config(context=(Interface, IPyAMSLayer), provides=IContextTitlePrefix)
+class ContextTitlePrefixAdapter(ContextRequestAdapter):
+    """Context title prefix adapter"""
+
+    @property
+    def prefix(self):
+        root = get_parent(self.context, ISiteRoot)
+        if root is not None:
+            configuration = IBackOfficeConfiguration(root, None)
+            if configuration is not None:
+                return configuration.short_title