Added search results portlet settings attribute to force canonical URL
authorThierry Florac <tflorac@ulthar.net>
Wed, 19 Dec 2018 11:02:20 +0100
changeset 1188 a3765dd8cbb8
parent 1187 b55bdf60c6cd
child 1189 26b86361e20b
Added search results portlet settings attribute to force canonical URL
src/pyams_content/features/search/portlet/__init__.py
src/pyams_content/features/search/portlet/interfaces.py
src/pyams_content/features/search/portlet/zmi/templates/search-preview.pt
--- a/src/pyams_content/features/search/portlet/__init__.py	Wed Dec 19 10:40:58 2018 +0100
+++ b/src/pyams_content/features/search/portlet/__init__.py	Wed Dec 19 11:02:20 2018 +0100
@@ -36,6 +36,7 @@
     """Search results portlet settings"""
 
     title = FieldProperty(ISearchResultsPortletSettings['title'])
+    force_canonical_url = FieldProperty(ISearchResultsPortletSettings['force_canonical_url'])
 
     @staticmethod
     def _get_items(request=None, limit=None, ignore_cache=False):
--- a/src/pyams_content/features/search/portlet/interfaces.py	Wed Dec 19 10:40:58 2018 +0100
+++ b/src/pyams_content/features/search/portlet/interfaces.py	Wed Dec 19 11:02:20 2018 +0100
@@ -12,11 +12,12 @@
 
 __docformat__ = 'restructuredtext'
 
+from zope.schema import Bool
+
+from pyams_content import _
 from pyams_i18n.schema import I18nTextLineField
 from pyams_portal.interfaces import IPortletSettings
 
-from pyams_content import _
-
 
 class ISearchResultsPortletSettings(IPortletSettings):
     """Search results portlet settings"""
@@ -24,3 +25,10 @@
     title = I18nTextLineField(title=_("Title"),
                               description=_("Portlet main title"),
                               required=False)
+
+    force_canonical_url = Bool(title=_("Force canonical URL?"),
+                               description=_("By default, internal links use a \"relative\" URL, which tries to "
+                                             "display link target in the current context; by using a canonical URL, "
+                                             "you can display target in it's attachment context (if defined)"),
+                               required=False,
+                               default=False)
--- a/src/pyams_content/features/search/portlet/zmi/templates/search-preview.pt	Wed Dec 19 10:40:58 2018 +0100
+++ b/src/pyams_content/features/search/portlet/zmi/templates/search-preview.pt	Wed Dec 19 11:02:20 2018 +0100
@@ -2,6 +2,10 @@
 	 tal:define="settings view.settings; global count 0;
 				 (items, count) settings.get_items(request, limit=10, ignore_cache=True);">
 	<strong>${i18n:settings.title}</strong>
+	<div class="padding-x-10">
+		<i class="fa fa-fw fa-${'check-' if settings.force_canonical_url else ''}square-o"></i>
+		<span i18n:translate="">Force canonical URL</span>
+	</div>
 	<div>
 		<span i18n:translate="">Extracted contents (limited to 10):</span>
 		<ul>