--- a/src/pyams_default_theme/features/search/portlet/__init__.py Tue Mar 26 11:28:19 2019 +0100
+++ b/src/pyams_default_theme/features/search/portlet/__init__.py Tue Mar 26 16:49:32 2019 +0100
@@ -21,11 +21,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 import _
-from pyams_default_theme.features.search.portlet.interfaces import ISearchResultRenderer, \
- ISearchResultsPortletDefaultRendererSettings
+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.shared.common.interfaces import ISharedContentHeadViewletManager
+from pyams_i18n.interfaces import II18n
from pyams_portal.interfaces import IPortalContext, IPortletRenderer
from pyams_portal.portlet import PortletRenderer
from pyams_skin.interfaces.viewlet import IBreadcrumbs
@@ -36,6 +36,8 @@
from pyams_utils.url import canonical_url, relative_url
from pyams_viewlet.viewlet import ViewContentProvider, Viewlet, viewlet_config
+from pyams_default_theme import _
+
#
# Search folder custom head specificities renderer
@@ -92,14 +94,41 @@
"""Disable breadcrumbs in search results view"""
+@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)
+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)
+def shared_content_result_target_adapter(context, request, view):
+ """Shared content result target URL adapter"""
+ if view.settings.force_canonical_url:
+ return canonical_url(context, request)
+ else:
+ return relative_url(context, request)
+
+
@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultRenderer)
@template_config(template='templates/search-result.pt', layer=IPyAMSUserLayer)
@implementer(ISearchResultsView)
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)
+ @property
+ def url(self):
+ 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)
+
+ @property
+ def header(self):
+ return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), ISearchResultHeader)
--- a/src/pyams_default_theme/features/search/portlet/interfaces.py Tue Mar 26 11:28:19 2019 +0100
+++ b/src/pyams_default_theme/features/search/portlet/interfaces.py Tue Mar 26 16:49:32 2019 +0100
@@ -13,15 +13,31 @@
__docformat__ = 'restructuredtext'
from zope.contentprovider.interfaces import IContentProvider
-from zope.interface import Interface
+from zope.interface import Interface, Attribute
from zope.schema import Bool
from pyams_default_theme import _
+class ISearchResultTitle(Interface):
+ """Search result title interface"""
+
+
+class ISearchResultHeader(Interface):
+ """Search result header interface"""
+
+
+class ISearchResultTarget(Interface):
+ """Search result target URL interface"""
+
+
class ISearchResultRenderer(IContentProvider):
"""Search result renderer interface"""
+ url = Attribute("Search result URL")
+ title = Attribute("Search result title")
+ header = Attribute("Search result header")
+
class ISearchResultsPortletDefaultRendererSettings(Interface):
"""Search results portlet default renderer settings interface"""
--- a/src/pyams_default_theme/features/search/portlet/templates/search-result.pt Tue Mar 26 11:28:19 2019 +0100
+++ b/src/pyams_default_theme/features/search/portlet/templates/search-result.pt Tue Mar 26 16:49:32 2019 +0100
@@ -1,4 +1,4 @@
-<tal:var define="target view.get_url(context)"
+<tal:var define="target view.url"
i18n:domain="pyams_default_theme">
<div class="thumbnail pull-left col-lg-3 col-md-3 col-sm-4 hidden-xs"
tal:define="illustration tales:pyams_illustration(context)"
@@ -14,12 +14,12 @@
</div>
<div>
<a href="${target}">
- <h3>${i18n:context.title}</h3>
+ <h3>${view.title}</h3>
</a>
<div class="breadcrumbs">${structure:tales:breadcrumbs(context)}</div>
<div class="tags">${structure:tales:tags(context)}</div>
<div class="header"
- tal:define="header i18n:context.header">
+ tal:define="header view.header">
${structure:tales:html(header)}
</div>
</div>