Added simple footer renderer
authorThierry Florac <tflorac@ulthar.net>
Wed, 18 Jul 2018 01:57:50 +0200
changeset 100 dd3a147af2d1
parent 99 dbc36a846021
child 101 9c1189405f90
Added simple footer renderer
src/pyams_default_theme/features/footer/__init__.py
src/pyams_default_theme/features/footer/interfaces.py
src/pyams_default_theme/features/footer/skin/__init__.py
src/pyams_default_theme/features/footer/skin/templates/simple-footer.pt
src/pyams_default_theme/features/footer/zmi/__init__.py
--- a/src/pyams_default_theme/features/footer/__init__.py	Wed Jul 18 01:57:37 2018 +0200
+++ b/src/pyams_default_theme/features/footer/__init__.py	Wed Jul 18 01:57:50 2018 +0200
@@ -16,12 +16,21 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.association.interfaces import ASSOCIATION_CONTAINER_KEY
 from pyams_content.features.footer.interfaces import IFooterTarget, IFooterSettings
+from pyams_content.features.menu.interfaces import IMenuLinksContainerTarget, IMenuLinksContainer
+from pyams_default_theme.features.footer.interfaces import ISimpleFooterRendererSettings, ISimpleFooterLinksMenu
 from pyams_default_theme.layer import IPyAMSDefaultLayer
+from zope.location.interfaces import ISublocations
 
 # import packages
+from persistent import Persistent
+from pyams_content.features.menu import Menu
+from pyams_utils.adapter import get_annotation_adapter, adapter_config, ContextAdapter
 from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import contentprovider_config, ViewContentProvider
+from zope.interface import implementer
+from zope.location import Location
 
 
 @contentprovider_config(name='pyams.footer', layer=IPyAMSDefaultLayer)
@@ -29,11 +38,16 @@
     """Footer content provider"""
 
     footer = None
+    renderer = None
 
     def update(self):
         parent = get_parent(self.context, IFooterTarget)
         if parent is not None:
-            self.footer = IFooterSettings(parent, None)
+            footer = self.footer = IFooterSettings(parent, None)
+            if footer is not None:
+                renderer = self.renderer = footer.get_renderer(self.request)
+                if renderer is not None:
+                    renderer.update()
 
     def render(self):
         if self.footer is None:
@@ -42,3 +56,34 @@
         if renderer is None:
             return ''
         return renderer.render()
+
+
+#
+# Simple footer renderer settings
+#
+
+SIMPLE_FOOTER_LINKS_KEY = '{0}::links'.format(ASSOCIATION_CONTAINER_KEY)
+
+
+@implementer(ISimpleFooterRendererSettings, IMenuLinksContainerTarget)
+class SimpleFooterRendererSettings(Persistent, Location):
+    """Simple footer renderer settings"""
+
+    @property
+    def links(self):
+        return get_annotation_adapter(self, SIMPLE_FOOTER_LINKS_KEY, Menu,
+                                      markers=ISimpleFooterLinksMenu, name='++ass++links')
+
+
+@adapter_config(name='links', context=ISimpleFooterRendererSettings, provides=IMenuLinksContainer)
+def simple_footer_links_adapter(context):
+    """Simple footer links adapter"""
+    return context.links
+
+
+@adapter_config(name='links', context=ISimpleFooterRendererSettings, provides=ISublocations)
+class SimpleFooterRendererSettingsSublocations(ContextAdapter):
+    """Simple footer renderer settings sub-locations adapter"""
+
+    def sublocations(self):
+        return self.context.links.values()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/footer/interfaces.py	Wed Jul 18 01:57:50 2018 +0200
@@ -0,0 +1,32 @@
+#
+# 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 IFooterRendererSettings
+
+# import packages
+from zope.interface import Interface, Attribute
+
+
+class ISimpleFooterRendererSettings(IFooterRendererSettings):
+    """Simple footer renderer settings"""
+
+    links = Attribute("Footer links")
+
+
+class ISimpleFooterLinksMenu(Interface):
+    """Simple footer links marker interface"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/footer/skin/__init__.py	Wed Jul 18 01:57:50 2018 +0200
@@ -0,0 +1,64 @@
+#
+# 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.component.association.interfaces import IAssociationInfo
+from pyams_content.features.footer.interfaces import IFooterTarget, IFooterRenderer, IFooterSettings, \
+    IFooterRendererSettings
+from pyams_default_theme.features.footer.interfaces import ISimpleFooterRendererSettings
+from pyams_skin.layer import IPyAMSLayer
+
+# import packages
+from pyams_content.features.footer.skin import BaseFooterRenderer
+from pyams_default_theme.features.footer import SimpleFooterRendererSettings
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+
+from pyams_default_theme import _
+
+
+SIMPLE_FOOTER_RENDERER_NAME = 'PyAMS simple header'
+
+
+#
+# Simple footer renderer
+#
+
+@adapter_config(name=SIMPLE_FOOTER_RENDERER_NAME, context=(IFooterTarget, IPyAMSLayer),
+                provides=IFooterRenderer)
+@adapter_config(name=SIMPLE_FOOTER_RENDERER_NAME, context=(IFooterSettings, IPyAMSLayer),
+                provides=IFooterRenderer)
+@template_config(template='templates/simple-footer.pt', layer=IPyAMSLayer)
+class SimpleFooterRenderer(BaseFooterRenderer):
+    """Simple footer renderer"""
+
+    name = SIMPLE_FOOTER_RENDERER_NAME
+    label = _("PyAMS simple footer with links")
+    weight = 1
+
+    settings_key = 'PyAMS::simple'
+    settings_interface = ISimpleFooterRendererSettings
+
+    @staticmethod
+    def get_link_info(link):
+        return IAssociationInfo(link)
+
+
+@adapter_config(context=SimpleFooterRenderer, provides=IFooterRendererSettings)
+def simple_footer_renderer_settings_factory(context):
+    """Simple footer renderer settings factory"""
+    return SimpleFooterRendererSettings()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/footer/skin/templates/simple-footer.pt	Wed Jul 18 01:57:50 2018 +0200
@@ -0,0 +1,14 @@
+<div class="footer footer-simple"
+	 tal:define="settings view.settings" i18n:domain="pyams_default_theme">
+	<ul class="nav nav-tabs" role="tablist">
+		<tal:loop repeat="link settings.links.get_visible_items(request)">
+			<li role="presentation">
+				<a tal:define="info view.get_link_info(link);
+							   href link.get_url(request);"
+				   tal:condition="href"
+				   tal:content="info.user_title"
+				   tal:attributes="href href">Link</a>
+			</li>
+		</tal:loop>
+	</ul>
+</div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/footer/zmi/__init__.py	Wed Jul 18 01:57:50 2018 +0200
@@ -0,0 +1,67 @@
+#
+# 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_default_theme.features.footer.interfaces import ISimpleFooterRendererSettings, ISimpleFooterLinksMenu
+from pyams_form.interfaces.form import IInnerSubForm
+from pyams_portal.interfaces import MANAGE_TEMPLATE_PERMISSION
+from pyams_skin.layer import IPyAMSLayer
+
+# import packages
+from pyams_content.features.footer.zmi import FooterSettingsRendererSettingsEditForm
+from pyams_content.features.menu.zmi import LinksTable, IMenuLinksView, MenuLinksView
+from pyams_utils.adapter import adapter_config
+from pyams_zmi.form import InnerAdminEditForm
+from z3c.form import field
+
+from pyams_default_theme import _
+
+
+@adapter_config(name='simple-footer-properties',
+                context=(ISimpleFooterRendererSettings, IPyAMSLayer, FooterSettingsRendererSettingsEditForm),
+                provides=IInnerSubForm)
+class SimpleFooterPropertiesEditForm(InnerAdminEditForm):
+    """Simple footer properties edit form"""
+
+    legend = None
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
+    weight = 1
+
+    fields = field.Fields(ISimpleFooterRendererSettings)
+
+
+#
+# Footer links table view
+#
+
+class LinksAssociationsTable(LinksTable):
+    """Simple footer links associations table"""
+
+    associations_name = 'links'
+
+
+@adapter_config(name='simple-footer-links',
+                context=(ISimpleFooterRendererSettings, IPyAMSLayer, FooterSettingsRendererSettingsEditForm),
+                provides=IInnerSubForm)
+@adapter_config(name='++ass++links', context=(ISimpleFooterLinksMenu, IPyAMSLayer), provides=IMenuLinksView)
+class SimpleFooterTabsView(MenuLinksView):
+    """Simple footer links view"""
+
+    title = _("Footer links")
+
+    table_class = LinksAssociationsTable
+    weight = 10