Added search results portlet settings attribute to force canonical URL
authorThierry Florac <tflorac@ulthar.net>
Wed, 19 Dec 2018 11:02:50 +0100
changeset 297 2d9623dc5c56
parent 296 a070719aef84
child 298 2e28f2f2a3d0
Added search results portlet settings attribute to force canonical URL
src/pyams_default_theme/features/search/portlet/__init__.py
src/pyams_default_theme/features/search/portlet/templates/search-results.pt
--- a/src/pyams_default_theme/features/search/portlet/__init__.py	Mon Dec 17 17:44:54 2018 +0100
+++ b/src/pyams_default_theme/features/search/portlet/__init__.py	Wed Dec 19 11:02:50 2018 +0100
@@ -19,6 +19,7 @@
 from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content.features.search.portlet import ISearchResultsPortletSettings
+from pyams_default_theme import _
 from pyams_default_theme.features.search.portlet.interfaces import ISearchResultsPortletDefaultRendererSettings
 from pyams_default_theme.interfaces import ISearchResultsView
 from pyams_portal.interfaces import IPortalContext, IPortletRenderer
@@ -26,10 +27,9 @@
 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.adapter import NullAdapter, adapter_config
 from pyams_utils.factory import factory_config
-
-from pyams_default_theme import _
+from pyams_utils.url import canonical_url, relative_url
 
 
 @factory_config(provided=ISearchResultsPortletDefaultRendererSettings)
@@ -58,6 +58,12 @@
             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)
+        else:
+            return relative_url(target, self.request)
+
 
 @adapter_config(context=(ILocation, IPyAMSUserLayer, ISearchResultsView), provides=IBreadcrumbs)
 class BreadcrumbsAdapter(NullAdapter):
--- a/src/pyams_default_theme/features/search/portlet/templates/search-results.pt	Mon Dec 17 17:44:54 2018 +0100
+++ b/src/pyams_default_theme/features/search/portlet/templates/search-results.pt	Wed Dec 19 11:02:50 2018 +0100
@@ -18,7 +18,7 @@
 			<hr />
 		</header>
 		<tal:loop repeat="item items">
-			<tal:var define="target tales:relative_url(item)">
+			<tal:var define="target view.get_url(item)">
 				<div class="thumbnail pull-left col-lg-3 col-md-3 col-sm-4 hidden-xs"
 					 tal:define="illustration tales:pyams_illustration(item)"
 					 tal:condition="illustration">