Added view items portlet renderer
authorThierry Florac <tflorac@ulthar.net>
Wed, 25 Sep 2019 10:27:19 +0200
changeset 464 6a70ef009b65
parent 463 7475b50516c8
child 465 e4397e6a6890
Added view items 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-summary.pt
--- a/src/pyams_default_theme/shared/view/portlet/__init__.py	Wed Sep 25 10:10:16 2019 +0200
+++ b/src/pyams_default_theme/shared/view/portlet/__init__.py	Wed Sep 25 10:27:19 2019 +0200
@@ -10,16 +10,14 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
-
 from persistent import Persistent
 from zope.container.contained import Contained
 from zope.interface import Interface
 from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings
-from pyams_default_theme import _
-from pyams_default_theme.shared.view.portlet.interfaces import IViewItemsPortletHorizontalRendererSettings, \
+from pyams_default_theme.shared.view.portlet.interfaces import \
+    IViewItemsPortletHorizontalRendererSettings, IViewItemsPortletSummaryRendererSettings, \
     IViewItemsPortletVerticalRendererSettings
 from pyams_portal.interfaces import IPortalContext, IPortletRenderer
 from pyams_portal.portlet import PortletRenderer
@@ -30,6 +28,11 @@
 from pyams_utils.url import canonical_url, relative_url
 
 
+__docformat__ = 'restructuredtext'
+
+from pyams_default_theme import _
+
+
 class BaseViewItemsPortletRenderer(PortletRenderer):
     """Base view items portlet renderer"""
 
@@ -56,9 +59,12 @@
 class ViewItemsPortletVerticalRendererSettings(Persistent, Contained):
     """View items portlet vertical renderer settings"""
 
-    display_illustrations = FieldProperty(IViewItemsPortletVerticalRendererSettings['display_illustrations'])
-    thumbnails_selection = FieldProperty(IViewItemsPortletVerticalRendererSettings['thumbnails_selection'])
-    display_breadcrumbs = FieldProperty(IViewItemsPortletVerticalRendererSettings['display_breadcrumbs'])
+    display_illustrations = FieldProperty(
+        IViewItemsPortletVerticalRendererSettings['display_illustrations'])
+    thumbnails_selection = FieldProperty(
+        IViewItemsPortletVerticalRendererSettings['thumbnails_selection'])
+    display_breadcrumbs = FieldProperty(
+        IViewItemsPortletVerticalRendererSettings['display_breadcrumbs'])
     display_tags = FieldProperty(IViewItemsPortletVerticalRendererSettings['display_tags'])
     paginate = FieldProperty(IViewItemsPortletVerticalRendererSettings['paginate'])
     page_size = FieldProperty(IViewItemsPortletVerticalRendererSettings['page_size'])
@@ -71,7 +77,7 @@
     """View items portlet vertical renderer"""
 
     label = _("Simple vertical view")
-    weight = 0
+    weight = 1
 
     settings_interface = IViewItemsPortletVerticalRendererSettings
 
@@ -84,7 +90,8 @@
 class ViewItemsPortletHorizontalRendererSettings(Persistent, Contained):
     """View items portlet horizontal renderer settings"""
 
-    thumbnails_selection = FieldProperty(IViewItemsPortletHorizontalRendererSettings['thumbnails_selection'])
+    thumbnails_selection = FieldProperty(
+        IViewItemsPortletHorizontalRendererSettings['thumbnails_selection'])
 
 
 @adapter_config(name='horizontal',
@@ -95,6 +102,35 @@
     """View items portlet horizontal renderer"""
 
     label = _("Simple horizontal thumbnails view")
-    weight = 1
+    weight = 2
 
     settings_interface = IViewItemsPortletHorizontalRendererSettings
+
+
+#
+# Summary-like portlet renderer
+#
+
+@factory_config(provided=IViewItemsPortletSummaryRendererSettings)
+class ViewItemsPortletSummaryRendererSettings(Persistent, Contained):
+    """View items portlet renderer summary renderer settings"""
+
+    display_illustrations = FieldProperty(
+        IViewItemsPortletSummaryRendererSettings['display_illustrations'])
+    thumbnails_selection = FieldProperty(
+        IViewItemsPortletSummaryRendererSettings['thumbnails_selection'])
+    paginate = FieldProperty(IViewItemsPortletSummaryRendererSettings['paginate'])
+    page_size = FieldProperty(IViewItemsPortletSummaryRendererSettings['page_size'])
+
+
+@adapter_config(name='summary',
+                context=(IPortalContext, IPyAMSLayer, Interface, IViewItemsPortletSettings),
+                provides=IPortletRenderer)
+@template_config(template='templates/view-items-summary.pt', layer=IPyAMSLayer)
+class ViewItemsPortletSummaryRenderer(BaseViewItemsPortletRenderer):
+    """View items portlet summary renderer"""
+
+    label = _("Vertical panels view")
+    weight = 3
+
+    settings_interface = IViewItemsPortletSummaryRendererSettings
--- a/src/pyams_default_theme/shared/view/portlet/interfaces.py	Wed Sep 25 10:10:16 2019 +0200
+++ b/src/pyams_default_theme/shared/view/portlet/interfaces.py	Wed Sep 25 10:27:19 2019 +0200
@@ -10,11 +10,12 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
+from zope.interface import Interface
+from zope.schema import Bool, Choice, Int
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
-from zope.interface import Interface
-from zope.schema import Bool, Int, Choice
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+
+__docformat__ = 'restructuredtext'
 
 from pyams_default_theme import _
 
@@ -33,7 +34,8 @@
     """View items portlet vertical renderer settings interface"""
 
     display_illustrations = Bool(title=_("Display illustrations?"),
-                                 description=_("If 'no', view contents will not display illustrations"),
+                                 description=_("If 'no', view contents will not display "
+                                               "illustrations"),
                                  required=True,
                                  default=True)
 
@@ -44,7 +46,8 @@
                                   default='pano')
 
     display_breadcrumbs = Bool(title=_("Display breadcrumbs?"),
-                               description=_("If 'no', view items breadcrumbs will not be displayed"),
+                               description=_("If 'no', view items breadcrumbs will not be "
+                                             "displayed"),
                                required=True,
                                default=True)
 
@@ -72,3 +75,29 @@
                                   vocabulary=VIEW_ITEMS_THUMBNAILS_VOCABULARY,
                                   required=True,
                                   default='portrait')
+
+
+class IViewItemsPortletSummaryRendererSettings(Interface):
+    """View items portlet summary renderer settings interface"""
+
+    display_illustrations = Bool(title=_("Display illustrations?"),
+                                 description=_("If 'no', view contents will not display "
+                                               "illustrations"),
+                                 required=True,
+                                 default=True)
+
+    thumbnails_selection = Choice(title=_("Thumbnails selection"),
+                                  description=_("Selection used to display images thumbnails"),
+                                  vocabulary=VIEW_ITEMS_THUMBNAILS_VOCABULARY,
+                                  required=True,
+                                  default='pano')
+
+    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=9)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/view/portlet/templates/view-items-summary.pt	Wed Sep 25 10:27:19 2019 +0200
@@ -0,0 +1,61 @@
+<div class="panels" i18n:domain="pyams_default_theme"
+	 tal:define="settings view.settings;
+				 renderer_settings view.renderer_settings;
+				 start int(request.params.get('vstart', 0));
+				 limit (start + renderer_settings.page_size) if renderer_settings.paginate else 999;
+				 items settings.get_items(request, limit);
+				 (has_items, results) tales:boolean_iter(items);"
+	 tal:condition="has_items">
+	<h2>${i18n:settings.title}</h2>
+	<div class="summary"
+		 tal:define="global count 0;
+					 selection renderer_settings.thumbnails_selection;">
+		<tal:loop repeat="item results">
+			<div class="result col-md-4 col-sm-6">
+				<tal:var define="global count count + 1;
+								 target view.get_url(item);
+								 illustration tales:pyams_illustration(item);">
+					<a href="${target}">
+						<tal:if define="image i18n:illustration.data;
+										alt i18n:illustration.alt_title;"
+								condition="image">
+							${structure:tales:picture(image, lg_thumb=selection, lg_width=4, md_thumb=selection, md_width=4,
+													  sm_thumb='pano', sm_width=6, xs_thumb='pano', xs_width=6, alt=alt)}
+						</tal:if>
+					</a>
+					<a class="caption"
+					   href="${target}">
+						<h3>${i18n:item.title}</h3>
+					</a>
+					<div class="header"
+						 tal:define="header i18n:item.header">
+						${structure:tales:html(header)}
+					</div>
+				</tal:var>
+			</div>
+			<div class="clearfix visible-md-block visible-lg-block"
+				 tal:condition="not:repeat['item'].number % 3"></div>
+			<div class="clearfix visible-sm-block"
+				 tal:condition="not:repeat['item'].number % 2"></div>
+		</tal:loop>
+		<div class="clearfix"></div>
+		<footer tal:condition="renderer_settings.paginate">
+			<ul class="pager">
+				<li class="previous"
+					tal:condition="start > 0">
+					<a href="${request.path_url}?vstart=${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}?vstart=${start + count}">
+						<i18n:var translate="">Next</i18n:var>
+						<span aria-hidden="true">&rarr;</span>
+					</a>
+				</li>
+			</ul>
+		</footer>
+	</div>
+</div>