Added shared content specificities support
authorThierry Florac <thierry.florac@onf.fr>
Fri, 28 Dec 2018 10:49:47 +0100
changeset 315 91448e576861
parent 314 422396b9b729
child 316 c12f6c3ac809
Added shared content specificities support
src/pyams_default_theme/shared/common/head.py
src/pyams_default_theme/shared/common/interfaces.py
src/pyams_default_theme/shared/common/portlet/specificities.py
src/pyams_default_theme/shared/common/portlet/templates/head.pt
src/pyams_default_theme/shared/common/specificities.py
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/head.py	Fri Dec 28 10:49:47 2018 +0100
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2008-2018 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'
+
+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
--- /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 <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'
+
+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"""
--- /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 <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'
+
+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()
--- 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 @@
 			<tal:var define="header tales:i18n(context, 'header', '')">${structure:tales:html(header)}</tal:var>
 		</div>
 	</div>
+	<tal:if condition="settings.display_specificities">
+		${structure:provider:pyams_content.custom_header}
+	</tal:if>
 </div>
\ No newline at end of file
--- /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 <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'
+
+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()
--- /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 @@
+<tal:var define="title i18n:context.title">
+	<h3 tal:condition="title">${title}</h3>
+	${structure:view.renderer.render()}
+</tal:var>