# HG changeset patch # User Thierry Florac # Date 1547032530 -3600 # Node ID 3eff0deae2616920971a31beae12be3243e2a15d # Parent 9f8b56eeb149f0dd5c277ddac8af91b614f67e62 Added method to check for user search query diff -r 9f8b56eeb149 -r 3eff0deae261 src/pyams_content/features/search/portlet/__init__.py --- a/src/pyams_content/features/search/portlet/__init__.py Tue Jan 08 16:15:45 2019 +0100 +++ b/src/pyams_content/features/search/portlet/__init__.py Wed Jan 09 12:15:30 2019 +0100 @@ -40,6 +40,11 @@ force_canonical_url = FieldProperty(ISearchResultsPortletSettings['force_canonical_url']) @staticmethod + def has_user_query(request): + params = request.params + return params.get('user_search', '').strip() or params.get('tag', '').strip() + + @staticmethod def _get_items(request=None, limit=None, ignore_cache=False): context = get_parent(request.context, ISearchFolder) if context is None: @@ -59,7 +64,7 @@ request=request) def get_items(self, request=None, limit=None, ignore_cache=False): - if not (self.allow_empty_query or request.params.get('user_search', '').strip()): + if not (self.allow_empty_query or self.has_user_query(request)): yield from iter(((), 0),) else: check, items = tee(SearchResultsPortletSettings._get_items(request, limit, ignore_cache)) diff -r 9f8b56eeb149 -r 3eff0deae261 src/pyams_content/features/search/portlet/interfaces.py --- a/src/pyams_content/features/search/portlet/interfaces.py Tue Jan 08 16:15:45 2019 +0100 +++ b/src/pyams_content/features/search/portlet/interfaces.py Wed Jan 09 12:15:30 2019 +0100 @@ -14,11 +14,10 @@ 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""" @@ -33,6 +32,9 @@ required=True, default=True) + def has_user_query(self): + """Check if user entered custom search arguments""" + 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, "