# HG changeset patch # User Thierry Florac # Date 1545990587 -3600 # Node ID 91448e5768610076a6ff3953f8d247d048a2dd41 # Parent 422396b9b729eb61e034fee07d92f899b5b1aaf6 Added shared content specificities support diff -r 422396b9b729 -r 91448e576861 src/pyams_default_theme/shared/common/head.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/common/head.py Fri Dec 28 10:49:47 2018 +0100 @@ -0,0 +1,37 @@ +# +# Copyright (c) 2008-2018 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' + +from zope.interface import Interface + +from pyams_default_theme.shared.common.interfaces import ICustomContentHeaderRenderer +from pyams_skin.layer import IPyAMSUserLayer +from pyams_viewlet.viewlet import contentprovider_config, ViewContentProvider + + +@contentprovider_config(name='pyams_content.custom_header', layer=IPyAMSUserLayer, view=Interface) +class CustomContentHeaderContentProvider(ViewContentProvider): + """Custom content header""" + + renderer = None + + def update(self): + super(CustomContentHeaderContentProvider, self).update() + registry = self.request.registry + self.renderer = renderer = registry.queryMultiAdapter((self.context, self.request, self.view), + ICustomContentHeaderRenderer) + if renderer is not None: + renderer.update() + + def render(self): + return '' if self.renderer is None else self.renderer.render() \ No newline at end of file diff -r 422396b9b729 -r 91448e576861 src/pyams_default_theme/shared/common/interfaces.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/common/interfaces.py Fri Dec 28 10:49:47 2018 +0100 @@ -0,0 +1,33 @@ +# +# Copyright (c) 2008-2018 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' + +from zope.contentprovider.interfaces import IContentProvider + +from pyams_portal.interfaces import IPortletSettings + + +class ICustomContentHeaderRenderer(IContentProvider): + """Custom content header renderer""" + + +class ISharedContentSpecificitiesPortletSettings(IPortletSettings): + """Shared content specificities portlet settings""" + + +class ICustomContentSpecificitiesRenderer(IContentProvider): + """Custom content specificities renderer""" + + +class ICustomContentSpecificitiesParagraphRenderer(IContentProvider): + """Custom content specificities paragraph renderer""" diff -r 422396b9b729 -r 91448e576861 src/pyams_default_theme/shared/common/portlet/specificities.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/common/portlet/specificities.py Fri Dec 28 10:49:47 2018 +0100 @@ -0,0 +1,49 @@ +# +# Copyright (c) 2008-2018 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' + +from zope.interface import Interface + +from pyams_default_theme.shared.common.interfaces import ISharedContentSpecificitiesPortletSettings, \ + ICustomContentSpecificitiesRenderer +from pyams_portal.interfaces import IPortalContext, IPortletRenderer +from pyams_portal.portlet import PortletRenderer +from pyams_skin.layer import IPyAMSLayer +from pyams_utils.adapter import adapter_config + +from pyams_default_theme import _ + + +# +# Shared content specificities portlet renderer +# + +@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, ISharedContentSpecificitiesPortletSettings), + provides=IPortletRenderer) +class SharedContentSpecificitiesPortletRenderer(PortletRenderer): + """Shared content specificities portlet default renderer""" + + label = _("Default specificities renderer") + + renderer = None + + def update(self): + super(SharedContentSpecificitiesPortletRenderer, self).update() + registry = self.request.registry + self.renderer = renderer = registry.queryMultiAdapter((self.context, self.request, self.view), + ICustomContentSpecificitiesRenderer) + if renderer is not None: + renderer.update() + + def render(self): + return '' if self.renderer is None else self.renderer.render() diff -r 422396b9b729 -r 91448e576861 src/pyams_default_theme/shared/common/portlet/templates/head.pt --- a/src/pyams_default_theme/shared/common/portlet/templates/head.pt Fri Dec 28 10:48:14 2018 +0100 +++ b/src/pyams_default_theme/shared/common/portlet/templates/head.pt Fri Dec 28 10:49:47 2018 +0100 @@ -9,4 +9,7 @@ ${structure:tales:html(header)} + + ${structure:provider:pyams_content.custom_header} + \ No newline at end of file diff -r 422396b9b729 -r 91448e576861 src/pyams_default_theme/shared/common/specificities.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/common/specificities.py Fri Dec 28 10:49:47 2018 +0100 @@ -0,0 +1,52 @@ +# +# Copyright (c) 2008-2018 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' + +from pyams_content.features.renderer.interfaces import IContentRenderer +from pyams_content.shared.common import IWfSharedContent +from pyams_content.shared.common.interfaces.specificities import ISharedContentSpecificitiesParagraph +from pyams_default_theme.features.renderer import BaseContentRenderer +from pyams_default_theme.shared.common.interfaces import ICustomContentSpecificitiesParagraphRenderer +from pyams_skin.layer import IPyAMSLayer +from pyams_template.template import template_config +from pyams_utils.adapter import adapter_config +from pyams_utils.traversing import get_parent + +from pyams_default_theme import _ + + +# +# Shared content specificities paragraph renderer +# + +@adapter_config(name='default', context=(ISharedContentSpecificitiesParagraph, IPyAMSLayer), provides=IContentRenderer) +@template_config(template='templates/specificities-paragraph.pt', layer=IPyAMSLayer) +class SharedContentSpecificitiesParagraphRenderer(BaseContentRenderer): + """Default shared content specificities paragraph renderer""" + + label = _("Default specificities paragraph renderer") + + renderer = None + + def update(self): + super(SharedContentSpecificitiesParagraphRenderer, self).update() + context = get_parent(self.context, IWfSharedContent) + if context is not None: + registry = self.request.registry + self.renderer = renderer = registry.queryMultiAdapter((context, self.request, self), + ICustomContentSpecificitiesParagraphRenderer) + if renderer is not None: + renderer.update() + + def render(self): + return '' if self.renderer is None else super(SharedContentSpecificitiesParagraphRenderer, self).render() diff -r 422396b9b729 -r 91448e576861 src/pyams_default_theme/shared/common/templates/specificities-paragraph.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/common/templates/specificities-paragraph.pt Fri Dec 28 10:49:47 2018 +0100 @@ -0,0 +1,4 @@ + +

${title}

+ ${structure:view.renderer.render()} +