Update configuration to get context title prefix
authorThierry Florac <thierry.florac@onf.fr>
Thu, 12 May 2016 10:38:47 +0200
changeset 134 d227e7037aa4
parent 133 00dd94c59eb0
child 135 419c021334c0
Update configuration to get context title prefix
src/pyams_skin/configuration.py
src/pyams_skin/interfaces/configuration.py
--- a/src/pyams_skin/configuration.py	Thu May 12 10:37:51 2016 +0200
+++ b/src/pyams_skin/configuration.py	Thu May 12 10:38:47 2016 +0200
@@ -17,6 +17,7 @@
 import pkg_resources
 
 # import interfaces
+from pyams_skin.interfaces import IContextTitlePrefix
 from pyams_skin.interfaces.configuration import IStaticConfiguration, IConfiguration, SKIN_CONFIGURATION_KEY, \
     IBackOfficeConfiguration, SKIN_BACK_CONFIGURATION_KEY
 from pyams_utils.interfaces.site import IStaticConfigurationManager, IConfigurationManager, IConfigurationFactory, \
@@ -33,6 +34,7 @@
 from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
 from pyramid.httpexceptions import HTTPNotFound
+from pyramid.threadlocal import get_current_registry
 from pyramid.view import view_config
 from zope.container.contained import Contained
 from zope.interface import implementer, Interface
@@ -163,6 +165,7 @@
     """Back-office manageable configuration"""
 
     title = FieldProperty(IBackOfficeConfiguration['title'])
+    short_title = FieldProperty(IBackOfficeConfiguration['short_title'])
     login_header = FieldProperty(IBackOfficeConfiguration['login_header'])
     login_footer = FieldProperty(IBackOfficeConfiguration['login_footer'])
     icon = FileProperty(IBackOfficeConfiguration['icon'])
@@ -170,6 +173,12 @@
     display_content_icon = FieldProperty(IBackOfficeConfiguration['display_content_icon'])
     display_shared_tool_title = FieldProperty(IBackOfficeConfiguration['display_shared_tool_title'])
 
+    @staticmethod
+    def get_title_prefix(request):
+        adapter = get_current_registry().queryMultiAdapter((request.context, request), IContextTitlePrefix)
+        if adapter is not None:
+            return adapter.prefix
+
 
 @adapter_config(context=IConfigurationManager, provides=IBackOfficeConfiguration)
 def BackOfficeConfigurationFactory(context):
--- a/src/pyams_skin/interfaces/configuration.py	Thu May 12 10:37:51 2016 +0200
+++ b/src/pyams_skin/interfaces/configuration.py	Thu May 12 10:38:47 2016 +0200
@@ -152,6 +152,13 @@
                      description=_("Application title visible in back-office"),
                      required=False)
 
+    short_title = TextLine(title=_("Short title"),
+                           description=_("Application short title visible as title prefix"),
+                           required=False)
+
+    def get_title_prefix(self, request):
+        """Get title prefix based on current navigation context"""
+
     login_header = Text(title=_("Login header"),
                         description=_("This reStructuredText text will be displayed in login page header"),
                         required=False)