Added header and footer content providers
authorThierry Florac <thierry.florac@onf.fr>
Fri, 18 May 2018 08:47:41 +0200
changeset 27 e908c952d5c9
parent 26 2fd0a1c3e4e5
child 28 1264ca1778e4
Added header and footer content providers
src/pyams_default_theme/features/__init__.py
src/pyams_default_theme/features/footer/__init__.py
src/pyams_default_theme/features/header/__init__.py
src/pyams_default_theme/templates/layout.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/__init__.py	Fri May 18 08:47:41 2018 +0200
@@ -0,0 +1,20 @@
+#
+# 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'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/footer/__init__.py	Fri May 18 08:47:41 2018 +0200
@@ -0,0 +1,44 @@
+#
+# 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'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.features.footer.interfaces import IFooterTarget, IFooterSettings
+from pyams_default_theme.layer import IPyAMSDefaultLayer
+
+# import packages
+from pyams_utils.traversing import get_parent
+from pyams_viewlet.viewlet import contentprovider_config, ViewContentProvider
+
+
+@contentprovider_config(name='pyams.footer', layer=IPyAMSDefaultLayer)
+class FooterContentProvider(ViewContentProvider):
+    """Footer content provider"""
+
+    footer = None
+
+    def update(self):
+        parent = get_parent(self.context, IFooterTarget)
+        if parent is not None:
+            self.footer = IFooterSettings(parent, None)
+
+    def render(self):
+        if self.footer is None:
+            return ''
+        renderer = self.footer.get_renderer(self.request)
+        if renderer is None:
+            return ''
+        return renderer.render()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/header/__init__.py	Fri May 18 08:47:41 2018 +0200
@@ -0,0 +1,44 @@
+#
+# 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'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.features.header.interfaces import IHeaderTarget, IHeaderSettings
+from pyams_default_theme.layer import IPyAMSDefaultLayer
+
+# import packages
+from pyams_utils.traversing import get_parent
+from pyams_viewlet.viewlet import contentprovider_config, ViewContentProvider
+
+
+@contentprovider_config(name='pyams.header', layer=IPyAMSDefaultLayer)
+class HeaderContentProvider(ViewContentProvider):
+    """Header content provider"""
+
+    header = None
+
+    def update(self):
+        parent = get_parent(self.context, IHeaderTarget)
+        if parent is not None:
+            self.header = IHeaderSettings(parent, None)
+
+    def render(self):
+        if self.header is None:
+            return ''
+        renderer = self.header.get_renderer(self.request)
+        if renderer is None:
+            return ''
+        return renderer.render()
--- a/src/pyams_default_theme/templates/layout.pt	Fri May 18 08:47:02 2018 +0200
+++ b/src/pyams_default_theme/templates/layout.pt	Fri May 18 08:47:41 2018 +0200
@@ -23,6 +23,11 @@
 
 </head>
 <body class="no-margin no-padding">
+
+	<!-- Page header -->
+	<div id="page-header" tal:content="structure provider:pyams.header">Header</div>
+	<!-- End page header -->
+
 	<!-- Main panel -->
 	<div id="main" class="no-margin" role="main">
 
@@ -37,5 +42,10 @@
 
 	</div>
 	<!-- end main panel -->
+
+	<!-- Page footer -->
+	<div id="page-footer" tal:content="structure provider:pyams.footer">Header</div>
+	<!-- End page footer -->
+
 </body>
 </html>