# HG changeset patch # User Thierry Florac # Date 1463043658 -7200 # Node ID 2dec7379f93526641b8df72edb7d9e650960fdfb # Parent cdad4eadfd43b152348ecf7fef92f56cc2231729 Added default context title prefix adapter diff -r cdad4eadfd43 -r 2dec7379f935 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 +# 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