# HG changeset patch # User Thierry Florac # Date 1545397073 -3600 # Node ID 66ef165934a9fecdfcb5f4435caff09605006eaf # Parent 2e28f2f2a3d02f6a0e6ceeb358bb87e343c94238 Added interface and default adapter to render search results diff -r 2e28f2f2a3d0 -r 66ef165934a9 src/pyams_default_theme/features/search/portlet/__init__.py --- a/src/pyams_default_theme/features/search/portlet/__init__.py Wed Dec 19 16:56:36 2018 +0100 +++ b/src/pyams_default_theme/features/search/portlet/__init__.py Fri Dec 21 13:57:53 2018 +0100 @@ -19,8 +19,10 @@ from zope.schema.fieldproperty import FieldProperty from pyams_content.features.search.portlet import ISearchResultsPortletSettings +from pyams_content.shared.common import IWfSharedContent from pyams_default_theme import _ -from pyams_default_theme.features.search.portlet.interfaces import ISearchResultsPortletDefaultRendererSettings +from pyams_default_theme.features.search.portlet.interfaces import ISearchResultRenderer, \ + ISearchResultsPortletDefaultRendererSettings from pyams_default_theme.interfaces import ISearchResultsView from pyams_portal.interfaces import IPortalContext, IPortletRenderer from pyams_portal.portlet import PortletRenderer @@ -30,6 +32,7 @@ from pyams_utils.adapter import NullAdapter, adapter_config from pyams_utils.factory import factory_config from pyams_utils.url import canonical_url, relative_url +from pyams_viewlet.viewlet import ViewContentProvider @factory_config(provided=ISearchResultsPortletDefaultRendererSettings) @@ -58,13 +61,27 @@ self.request.GET['length'] = '999' super(SearchResultsPortletDefaultRenderer, self).update() - def get_url(self, target): - if self.settings.force_canonical_url: - return canonical_url(target, self.request) + def render_item(self, item): + renderer = self.request.registry.queryMultiAdapter((item, self.request, self), ISearchResultRenderer) + if renderer is not None: + renderer.update() + return renderer.render() else: - return relative_url(target, self.request) + return '' @adapter_config(context=(ILocation, IPyAMSUserLayer, ISearchResultsView), provides=IBreadcrumbs) class BreadcrumbsAdapter(NullAdapter): """Disable breadcrumbs in search results view""" + + +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultRenderer) +@template_config(template='templates/search-result.pt', layer=IPyAMSUserLayer) +class WfSharedContentSearchResultRenderer(ViewContentProvider): + """Shared content search result renderer""" + + def get_url(self, target): + if self.view.settings.force_canonical_url: + return canonical_url(target, self.request) + else: + return relative_url(target, self.request) diff -r 2e28f2f2a3d0 -r 66ef165934a9 src/pyams_default_theme/features/search/portlet/interfaces.py --- a/src/pyams_default_theme/features/search/portlet/interfaces.py Wed Dec 19 16:56:36 2018 +0100 +++ b/src/pyams_default_theme/features/search/portlet/interfaces.py Fri Dec 21 13:57:53 2018 +0100 @@ -12,12 +12,17 @@ __docformat__ = 'restructuredtext' +from zope.contentprovider.interfaces import IContentProvider from zope.interface import Interface from zope.schema import Bool from pyams_default_theme import _ +class ISearchResultRenderer(IContentProvider): + """Search result renderer interface""" + + class ISearchResultsPortletDefaultRendererSettings(Interface): """Search results portlet default renderer settings interface""" diff -r 2e28f2f2a3d0 -r 66ef165934a9 src/pyams_default_theme/features/search/portlet/templates/search-result.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-result.pt Fri Dec 21 13:57:53 2018 +0100 @@ -0,0 +1,26 @@ + + +
+ +

${i18n:context.title}

+
+ +
${structure:tales:tags(context)}
+
+ ${structure:tales:html(header)} +
+
+
diff -r 2e28f2f2a3d0 -r 66ef165934a9 src/pyams_default_theme/features/search/portlet/templates/search-results.pt --- a/src/pyams_default_theme/features/search/portlet/templates/search-results.pt Wed Dec 19 16:56:36 2018 +0100 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-results.pt Fri Dec 21 13:57:53 2018 +0100 @@ -18,31 +18,7 @@
- - -
- -

${i18n:item.title}

-
- -
${structure:tales:tags(item)}
-
- ${structure:tales:html(header)} -
-
-
+ ${structure:view.render_item(item)}