Updated default view portlet renderer
authorThierry Florac <tflorac@ulthar.net>
Wed, 28 Nov 2018 09:51:51 +0100
changeset 261 5ecc6a3743e9
parent 260 eac829fbf7f6
child 262 afe9d8d8692d
Updated default view portlet renderer
src/pyams_default_theme/shared/view/portlet/__init__.py
src/pyams_default_theme/shared/view/portlet/interfaces.py
src/pyams_default_theme/shared/view/portlet/templates/view-items-list.pt
--- a/src/pyams_default_theme/shared/view/portlet/__init__.py	Wed Nov 28 09:51:09 2018 +0100
+++ b/src/pyams_default_theme/shared/view/portlet/__init__.py	Wed Nov 28 09:51:51 2018 +0100
@@ -12,23 +12,33 @@
 
 __docformat__ = 'restructuredtext'
 
+from persistent import Persistent
+from zope.container.contained import Contained
+from zope.interface import Interface, implementer
+from zope.schema.fieldproperty import FieldProperty
 
-# import standard library
-
-# import interfaces
 from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings
+from pyams_default_theme.shared.view.portlet.interfaces import IViewItemsPortletVerticalRendererSettings
 from pyams_portal.interfaces import IPortalContext, IPortletRenderer
+from pyams_portal.portlet import PortletRenderer
 from pyams_skin.layer import IPyAMSLayer
-
-# import packages
-from pyams_portal.portlet import PortletRenderer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
-from zope.interface import Interface
+from pyams_utils.factory import factory_config
 
 from pyams_default_theme import _
 
 
+@factory_config(provided=IViewItemsPortletVerticalRendererSettings)
+@implementer(IViewItemsPortletVerticalRendererSettings)
+class ViewItemsPortletVerticalRendererSettings(Persistent, Contained):
+    """View items portlet renderer settings"""
+
+    display_illustrations = FieldProperty(IViewItemsPortletVerticalRendererSettings['display_illustrations'])
+    paginate = FieldProperty(IViewItemsPortletVerticalRendererSettings['paginate'])
+    page_size = FieldProperty(IViewItemsPortletVerticalRendererSettings['page_size'])
+
+
 @adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, IViewItemsPortletSettings),
                 provides=IPortletRenderer)
 @template_config(template='templates/view-items-list.pt', layer=IPyAMSLayer)
@@ -36,3 +46,6 @@
     """View items portlet renderer"""
 
     label = _("Simple vertical view")
+    weight = 0
+
+    settings_interface = IViewItemsPortletVerticalRendererSettings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/view/portlet/interfaces.py	Wed Nov 28 09:51:51 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 zope.schema import Bool, Int
+
+from pyams_default_theme import _
+
+
+class IViewItemsPortletVerticalRendererSettings(Interface):
+    """View items portlet vertical renderer settings interface"""
+
+    display_illustrations = Bool(title=_("Display illustrations?"),
+                                 description=_("If 'no', view contents will not display illustrations"),
+                                 required=True,
+                                 default=True)
+
+    paginate = Bool(title=_("Paginate?"),
+                    description=_("If 'no', results pagination will be disabled"),
+                    required=True,
+                    default=True)
+
+    page_size = Int(title=_("Page size"),
+                    description=_("Number of items per page, if pagination is enabled"),
+                    required=False,
+                    default=10)
--- a/src/pyams_default_theme/shared/view/portlet/templates/view-items-list.pt	Wed Nov 28 09:51:09 2018 +0100
+++ b/src/pyams_default_theme/shared/view/portlet/templates/view-items-list.pt	Wed Nov 28 09:51:51 2018 +0100
@@ -1,6 +1,60 @@
-<ul>
-	<li tal:repeat="item view.settings.get_items(request)">
-		<a tal:attributes="href tales:relative_url(item)"
-		   tal:content="i18n:item.title">Title</a>
-	</li>
-</ul>
+<div tal:define="settings view.settings;
+				 renderer_settings view.renderer_settings;"
+	 i18n:domain="pyams_default_theme">
+	<h2>${i18n:settings.title}</h2>
+	<div class="search-results"
+		 tal:define="start int(request.params.get('start', 0));
+					 limit (start + renderer_settings.page_size) if renderer_settings.paginate else 999;
+					 items settings.get_items(request, limit);
+					 global count 0;">
+		<tal:loop repeat="item items">
+			<div tal:define="global count count +1;
+							 target tales:relative_url(item);">
+				<tal:if condition="renderer_settings.display_illustrations">
+					<div class="thumbnail pull-left col-lg-3 col-md-3 col-sm-4 hidden-xs"
+						 tal:define="illustration tales:pyams_illustration(item)"
+						 tal:condition="illustration">
+						<a href="${target}">
+							<tal:if define="image i18n:illustration.data;
+											alt i18n:illustration.alt_title;"
+									condition="image">
+								${structure:tales:picture(image, lg_thumb='pano', lg_width=3, md_thumb='pano', md_width=3, sm_thumb='pano',
+														  sm_width=4, xs_thumb='pano', xs_width=12, alt=alt, css_class='result_media')}
+							</tal:if>
+						</a>
+					</div>
+				</tal:if>
+				<div>
+					<a href="${target}">
+						<h3>${i18n:item.title}</h3>
+					</a>
+					<div class="breadcrumbs">${structure:tales:breadcrumbs(item)}</div>
+					<div class="tags">${structure:tales:tags(item)}</div>
+					<div class="header"
+						 tal:define="header i18n:item.header">
+						${structure:tales:html(header)}
+					</div>
+				</div>
+			</div>
+			<div class="clearfix"></div>
+		</tal:loop>
+		<footer tal:condition="renderer_settings.paginate">
+			<ul class="pager">
+				<li class="previous"
+					tal:condition="start > 0">
+					<a href="${request.path_url}?start=${start - renderer_settings.page_size}">
+						<span aria-hidden="true">&larr;</span>
+						<i18n:var translate="">Previous</i18n:var>
+					</a>
+				</li>
+				<li class="next"
+					tal:condition="count == renderer_settings.page_size">
+					<a href="${request.path_url}?start=${start + count}">
+						<i18n:var translate="">Next</i18n:var>
+						<span aria-hidden="true">&rarr;</span>
+					</a>
+				</li>
+			</ul>
+		</footer>
+	</div>
+</div>