# HG changeset patch # User Thierry Florac # Date 1569398757 -7200 # Node ID 0aebe2d107ace70e6ab310bb0f7fbbca2362690b # Parent 77cec5c9ef84d299eb4b326dde7f7bc5d36e1322 Added search results portlet renderer diff -r 77cec5c9ef84 -r 0aebe2d107ac src/pyams_default_theme/features/search/portlet/__init__.py --- a/src/pyams_default_theme/features/search/portlet/__init__.py Tue Sep 17 12:00:26 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/__init__.py Wed Sep 25 10:05:57 2019 +0200 @@ -10,8 +10,6 @@ # FOR A PARTICULAR PURPOSE. # -__docformat__ = 'restructuredtext' - from persistent import Persistent from zope.container.contained import Contained from zope.interface import Interface, implementer @@ -21,9 +19,11 @@ from pyams_content.features.search import ISearchFolder from pyams_content.features.search.portlet import ISearchResultsPortletSettings from pyams_content.shared.common import IWfSharedContent -from pyams_default_theme.features.search.portlet.interfaces import ISearchResultHeader, ISearchResultRenderer, \ - ISearchResultTarget, ISearchResultTitle, ISearchResultsPortletDefaultRendererSettings -from pyams_default_theme.interfaces import ISearchResultsView +from pyams_default_theme.features.search.portlet.interfaces import ISearchResultHeader, \ + ISearchResultRenderer, ISearchResultTarget, ISearchResultTitle, \ + ISearchResultsPortletDefaultRendererSettings, ISearchResultsPortletPanelsRendererSettings, \ + ISearchResultsPortletRendererBaseSettings +from pyams_default_theme.interfaces import ISearchResultsPanelView, ISearchResultsView from pyams_default_theme.shared.common.interfaces import ISharedContentHeadViewletManager from pyams_i18n.interfaces import II18n from pyams_portal.interfaces import IPortalContext, IPortletRenderer @@ -36,6 +36,9 @@ from pyams_utils.url import canonical_url, relative_url from pyams_viewlet.viewlet import ViewContentProvider, Viewlet, viewlet_config + +__docformat__ = 'restructuredtext' + from pyams_default_theme import _ @@ -43,45 +46,43 @@ # Search folder custom head specificities renderer # -@viewlet_config(name='search-folder-head', context=ISearchFolder, layer=IPyAMSUserLayer, view=Interface, - manager=ISharedContentHeadViewletManager, weight=1) +@viewlet_config(name='search-folder-head', context=ISearchFolder, layer=IPyAMSUserLayer, + view=Interface, manager=ISharedContentHeadViewletManager, weight=1) @template_config(template='templates/folder-head-specificities.pt', layer=IPyAMSUserLayer) class SearchFolderHeadViewlet(Viewlet): """Search folder head specificities viewlet""" # -# Search results portlet renderers +# Search results portlet base settings and renderers # -@factory_config(provided=ISearchResultsPortletDefaultRendererSettings) -class SearchResultsPortletDefaultRendererSettings(Persistent, Contained): - """Search results portlet default renderer settings""" +@implementer(ISearchResultsPortletRendererBaseSettings) +class SearchResultsPortletRendererBaseSettings(Persistent, Contained): + """Search results portlet base renderer settings""" - display_results_count = FieldProperty(ISearchResultsPortletDefaultRendererSettings['display_results_count']) - allow_sorting = FieldProperty(ISearchResultsPortletDefaultRendererSettings['allow_sorting']) - allow_pagination = FieldProperty(ISearchResultsPortletDefaultRendererSettings['allow_pagination']) + display_results_count = FieldProperty( + ISearchResultsPortletRendererBaseSettings['display_results_count']) + allow_sorting = FieldProperty(ISearchResultsPortletRendererBaseSettings['allow_sorting']) + allow_pagination = FieldProperty(ISearchResultsPortletRendererBaseSettings['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""" +class SearchResultsPortletBaseRenderer(PortletRenderer): + """Search results portlet base renderer""" - label = _("Default search results") - - settings_interface = ISearchResultsPortletDefaultRendererSettings + default_page_length = 10 def update(self): settings = self.renderer_settings if not settings.allow_pagination: self.request.GET['length'] = '999' - super(SearchResultsPortletDefaultRenderer, self).update() + elif 'length' not in self.request.params: + self.request.GET['length'] = str(self.default_page_length) + super(SearchResultsPortletBaseRenderer, self).update() def render_item(self, item): - renderer = self.request.registry.queryMultiAdapter((item, self.request, self), ISearchResultRenderer) + renderer = self.request.registry.queryMultiAdapter((item, self.request, self), + ISearchResultRenderer) if renderer is not None: renderer.update() return renderer.render() @@ -89,24 +90,79 @@ return '' +# +# Search results portlet default renderer +# + +@factory_config(provided=ISearchResultsPortletDefaultRendererSettings) +class SearchResultsPortletDefaultRendererSettings(SearchResultsPortletRendererBaseSettings): + """Search results portlet default renderer settings""" + + +@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, ISearchResultsPortletSettings), + provides=IPortletRenderer) +@template_config(template='templates/search-results.pt', layer=IPyAMSLayer) +@implementer(ISearchResultsView) +class SearchResultsPortletDefaultRenderer(SearchResultsPortletBaseRenderer): + """Search results portlet default renderer""" + + label = _("Default search results") + + settings_interface = ISearchResultsPortletDefaultRendererSettings + + +# +# Search results portlet panels renderer +# + +@factory_config(provided=ISearchResultsPortletPanelsRendererSettings) +class SearchResultsPortletPanelsRendererSettings(SearchResultsPortletRendererBaseSettings): + """Search results portlet panel renderer settings""" + + button_title = FieldProperty(ISearchResultsPortletPanelsRendererSettings['button_title']) + + +@adapter_config(name='panels', + context=(IPortalContext, IPyAMSLayer, Interface, ISearchResultsPortletSettings), + provides=IPortletRenderer) +@template_config(template='templates/search-panels.pt', layer=IPyAMSLayer) +@implementer(ISearchResultsPanelView) +class SearchResultsPortletPanelsRenderer(SearchResultsPortletBaseRenderer): + """Search results portlet panels renderer""" + + label = _("Paneled search results") + + settings_interface = ISearchResultsPortletPanelsRendererSettings + default_page_length = 9 + + weight = 20 + + +# +# Search results adapters +# + @adapter_config(context=(ILocation, IPyAMSUserLayer, ISearchResultsView), provides=IBreadcrumbs) class BreadcrumbsAdapter(NullAdapter): """Disable breadcrumbs in search results view""" -@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultTitle) +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), + provides=ISearchResultTitle) def shared_content_result_title_adapter(context, request, view): """Shared content result title adapter""" return II18n(context).query_attribute('title', request=request) -@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultHeader) +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), + provides=ISearchResultHeader) def shared_content_result_header_adapter(context, request, view): """Shared content result header adapter""" return II18n(context).query_attribute('header', request=request) -@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultTarget) +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), + provides=ISearchResultTarget) def shared_content_result_target_adapter(context, request, view): """Shared content result target URL adapter""" if view.settings.force_canonical_url: @@ -115,7 +171,8 @@ return relative_url(context, request) -@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultRenderer) +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), + provides=ISearchResultRenderer) @template_config(template='templates/search-result.pt', layer=IPyAMSUserLayer) @implementer(ISearchResultsView) class WfSharedContentSearchResultRenderer(ViewContentProvider): @@ -123,12 +180,22 @@ @property def url(self): - return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), ISearchResultTarget) + return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), + ISearchResultTarget) @property def title(self): - return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), ISearchResultTitle) + return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), + ISearchResultTitle) @property def header(self): - return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), ISearchResultHeader) + return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), + ISearchResultHeader) + + +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsPanelView), + provides=ISearchResultRenderer) +@template_config(template='templates/search-panel.pt', layer=IPyAMSUserLayer) +class WfSharedContentSearchResultPanelRenderer(WfSharedContentSearchResultRenderer): + """Shared content search result panel renderer""" diff -r 77cec5c9ef84 -r 0aebe2d107ac src/pyams_default_theme/features/search/portlet/interfaces.py --- a/src/pyams_default_theme/features/search/portlet/interfaces.py Tue Sep 17 12:00:26 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/interfaces.py Wed Sep 25 10:05:57 2019 +0200 @@ -9,6 +9,8 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from pyams_i18n.schema import I18nTextLineField + __docformat__ = 'restructuredtext' @@ -39,8 +41,8 @@ header = Attribute("Search result header") -class ISearchResultsPortletDefaultRendererSettings(Interface): - """Search results portlet default renderer settings interface""" +class ISearchResultsPortletRendererBaseSettings(Interface): + """Search results portlet renderer base settings interface""" display_results_count = Bool(title=_("Display results count?"), description=_("If 'no', results count will not be displayed"), @@ -56,3 +58,18 @@ description=_("If 'no', results will not be paginated"), required=True, default=True) + + +class ISearchResultsPortletDefaultRendererSettings(ISearchResultsPortletRendererBaseSettings): + """Search results portlet default renderer settings interface""" + + +class ISearchResultsPortletPanelsRendererSettings(ISearchResultsPortletRendererBaseSettings): + """Search results portlet panels renderer settings interface""" + + button_title = I18nTextLineField(title=_("Button's title"), + description=_("Navigation button's title is normally defined " + "based on target's content type; you can " + "override this label by giving a custom title " + "here"), + required=False) diff -r 77cec5c9ef84 -r 0aebe2d107ac src/pyams_default_theme/features/search/portlet/templates/search-panel.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-panel.pt Wed Sep 25 10:05:57 2019 +0200 @@ -0,0 +1,33 @@ + + +
+ +

${view.title}

+
+
+ ${structure:tales:html(header)} +
+ +
+
\ No newline at end of file diff -r 77cec5c9ef84 -r 0aebe2d107ac src/pyams_default_theme/features/search/portlet/templates/search-panels.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-panels.pt Wed Sep 25 10:05:57 2019 +0200 @@ -0,0 +1,105 @@ +
+

${i18n:settings.title}

+
+ + + + + +
+
+
+
+ + ${count} result(s) found + + + No result found! + +
+
+ +
+
+ Page length:  + +
+
+
+
+ +
+ ${structure:view.render_item(item)} +
+
+
+
+
+
+
+ +
+
+
diff -r 77cec5c9ef84 -r 0aebe2d107ac src/pyams_default_theme/features/search/portlet/templates/search-result.pt --- a/src/pyams_default_theme/features/search/portlet/templates/search-result.pt Tue Sep 17 12:00:26 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-result.pt Wed Sep 25 10:05:57 2019 +0200 @@ -23,4 +23,4 @@ ${structure:tales:html(header)} - + \ No newline at end of file diff -r 77cec5c9ef84 -r 0aebe2d107ac src/pyams_default_theme/features/search/portlet/templates/search-results.pt --- a/src/pyams_default_theme/features/search/portlet/templates/search-results.pt Tue Sep 17 12:00:26 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-results.pt Wed Sep 25 10:05:57 2019 +0200 @@ -1,5 +1,7 @@

${i18n:settings.title}

@@ -8,11 +10,11 @@ - - + +
+ tal:define="(items, count) settings.get_items(request, start, length)">
@@ -59,7 +61,7 @@