Added search results portlet
authorThierry Florac <thierry.florac@onf.fr>
Tue, 27 Nov 2018 08:51:14 +0100
changeset 256 ab68305914ef
parent 255 20b80d2c592d
child 257 cc4ae9a70a17
Added search results portlet
src/pyams_default_theme/features/search/__init__.py
src/pyams_default_theme/features/search/portlet/__init__.py
src/pyams_default_theme/features/search/portlet/interfaces.py
src/pyams_default_theme/features/search/portlet/templates/search-results.pt
--- a/src/pyams_default_theme/features/search/__init__.py	Mon Nov 26 11:05:48 2018 +0100
+++ b/src/pyams_default_theme/features/search/__init__.py	Tue Nov 27 08:51:14 2018 +0100
@@ -13,10 +13,12 @@
 __docformat__ = 'restructuredtext'
 
 from pyams_content.features.search.interfaces import ISearchFolder
+from pyams_content.shared.site import ISiteElementNavigation
 from pyams_default_theme.interfaces import IContentSummaryInfo
-from pyams_content.shared.site import ISiteElementNavigation
 from pyams_i18n.interfaces import II18n
+from pyams_skin.interfaces.viewlet import IBreadcrumbItem
 from pyams_skin.layer import IPyAMSUserLayer
+from pyams_skin.viewlet.breadcrumb import BreadcrumbItem
 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
 from pyams_utils.interfaces.url import IRelativeURL
 from pyams_utils.url import absolute_url
@@ -44,6 +46,17 @@
         return IWorkflowPublicationInfo(self.context).is_visible(self.request)
 
 
+@adapter_config(context=(ISearchFolder, IPyAMSUserLayer), provides=IBreadcrumbItem)
+class SearchFolderBreadcumbAdapter(BreadcrumbItem):
+    """Search folder breadcrumb adapter"""
+
+    @property
+    def label(self):
+        return II18n(self.context).query_attribute('short_name', request=self.request)
+
+    url = None
+
+
 @adapter_config(context=(ISearchFolder, IPyAMSUserLayer), provides=IContentSummaryInfo)
 class SearchFolderSummaryAdapter(ContextRequestAdapter):
     """Search folder summary adapter"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/search/portlet/__init__.py	Tue Nov 27 08:51:14 2018 +0100
@@ -0,0 +1,59 @@
+#
+# 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 persistent import Persistent
+from zope.container.contained import Contained
+from zope.interface import Interface, implementer
+from zope.location import ILocation
+from zope.schema.fieldproperty import FieldProperty
+
+from pyams_content.features.search.portlet import ISearchResultsPortletSettings
+from pyams_default_theme.features.search.portlet.interfaces import ISearchResultsPortletDefaultRendererSettings
+from pyams_default_theme.interfaces import ISearchResultsView
+from pyams_portal.interfaces import IPortalContext, IPortletRenderer
+from pyams_portal.portlet import PortletRenderer
+from pyams_skin.interfaces.viewlet import IBreadcrumbs
+from pyams_skin.layer import IPyAMSLayer, IPyAMSUserLayer
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config, NullAdapter
+from pyams_utils.factory import factory_config
+
+from pyams_default_theme import _
+
+
+@implementer(ISearchResultsPortletDefaultRendererSettings)
+@factory_config(provided=ISearchResultsPortletDefaultRendererSettings)
+class SearchResultsPortletDefaultRendererSettings(Persistent, Contained):
+    """Search results portlet default renderer settings"""
+
+    display_results_count = FieldProperty(ISearchResultsPortletDefaultRendererSettings['display_results_count'])
+    allow_sorting = FieldProperty(ISearchResultsPortletDefaultRendererSettings['allow_sorting'])
+    allow_pagination = FieldProperty(ISearchResultsPortletDefaultRendererSettings['allow_pagination'])
+
+
+@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, ISearchResultsPortletSettings),
+                provides=IPortletRenderer)
+@template_config(template='templates/search-results.pt', layer=IPyAMSLayer)
+@implementer(ISearchResultsView)
+class SearchResultsPortletDefaultRenderer(PortletRenderer):
+    """Search results portlet default renderer"""
+
+    label = _("Default search results")
+
+    settings_interface = ISearchResultsPortletDefaultRendererSettings
+
+
+@adapter_config(context=(ILocation, IPyAMSUserLayer, ISearchResultsView), provides=IBreadcrumbs)
+class BreadcrumbsAdapter(NullAdapter):
+    """Disable breadcrumbs in search results view"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/search/portlet/interfaces.py	Tue Nov 27 08:51:14 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
+
+from pyams_default_theme import _
+
+
+class ISearchResultsPortletDefaultRendererSettings(Interface):
+    """Search results portlet default renderer settings interface"""
+
+    display_results_count = Bool(title=_("Display results count?"),
+                                 description=_("If 'no', results count will not be displayed"),
+                                 required=True,
+                                 default=True)
+
+    allow_sorting = Bool(title=_("Allow results sorting?"),
+                         description=_("If 'no', results will not be sortable"),
+                         required=True,
+                         default=True)
+
+    allow_pagination = Bool(title=_("Allow pagination?"),
+                            description=_("If 'no', results will not be paginated"),
+                            required=True,
+                            default=True)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/search/portlet/templates/search-results.pt	Tue Nov 27 08:51:14 2018 +0100
@@ -0,0 +1,31 @@
+<div tal:define="settings view.settings" i18n:domain="pyams_default_theme">
+	<h2>${i18n:settings.title}</h2>
+	<div class="search-results">
+		<tal:loop repeat="item settings.get_items(request)">
+			<tal:var define="target tales:relative_url(item)">
+				<div class="thumbnail pull-left col-lg-3 col-md-3 col-sm-4 hidden-xs">
+					<a tal:define="illustration tales:pyams_illustration(item)"
+					   tal:condition="illustration"
+					   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>
+				<div>
+					<h3>${i18n:item.title}</h3>
+					<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>
+			</tal:var>
+			<div class="clearfix"></div>
+		</tal:loop>
+	</div>
+</div>
\ No newline at end of file