# HG changeset patch # User Thierry Florac # Date 1593772069 -7200 # Node ID 8184dadefc8b579b543c3eaaaeb63ba84406e342 # Parent ed31bfcedddaa199606be61e5c35f03c20ae92ce Added collections to search engines diff -r ed31bfceddda -r 8184dadefc8b src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.mo Binary file src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.mo has changed diff -r ed31bfceddda -r 8184dadefc8b src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po --- a/src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po Wed Jul 01 18:05:38 2020 +0200 +++ b/src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po Fri Jul 03 12:27:49 2020 +0200 @@ -3379,11 +3379,11 @@ #: src/pyams_content/features/search/zmi/manager.py:45 msgid "Search settings..." -msgstr "Moteur de recherche" +msgstr "Moteurs de recherche" #: src/pyams_content/features/search/zmi/manager.py:59 msgid "Search engine settings" -msgstr "Paramétrage du moteur de recherche" +msgstr "Paramétrage des moteurs de recherche" #: src/pyams_content/features/search/zmi/manager.py:74 msgid "Enable search by tag" diff -r ed31bfceddda -r 8184dadefc8b src/pyams_content/root/zmi/search.py --- a/src/pyams_content/root/zmi/search.py Wed Jul 01 18:05:38 2020 +0200 +++ b/src/pyams_content/root/zmi/search.py Fri Jul 03 12:27:49 2020 +0200 @@ -23,6 +23,7 @@ from zope.schema import Choice, Datetime, List from pyams_catalog.query import CatalogResultSet +from pyams_content.component.theme import ICollectionsManager from pyams_content.component.theme.interfaces import ITagsManager from pyams_content.profile.interfaces import IAdminProfile from pyams_content.root import ISiteRoot @@ -177,6 +178,9 @@ tags = ThesaurusTermsListField(title=_("Tags"), required=False) + collections = ThesaurusTermsListField(title=_("Collections"), + required=False) + @template_config(template='templates/advanced-search.pt', layer=IPyAMSLayer) @implementer(IInnerPage) @@ -192,6 +196,7 @@ fields = field.Fields(ISiteRootAdvancedSearchFields) fields['tags'].widgetFactory = ThesaurusTermsTreeFieldWidget + fields['collections'].widgetFactory = ThesaurusTermsTreeFieldWidget ajax_handler = 'advanced-search-results.html' def updateWidgets(self, prefix=None): @@ -201,6 +206,11 @@ manager = ITagsManager(self.request.root) widget.thesaurus_name = manager.thesaurus_name widget.extract_name = manager.extract_name + if 'collections' in self.widgets: + widget = self.widgets['collections'] + manager = ICollectionsManager(self.request.root) + widget.thesaurus_name = manager.thesaurus_name + widget.extract_name = manager.extract_name @adapter_config(context=(ISiteRoot, IPyAMSLayer, SiteRootAdvancedSearchForm), provides=IContentSearch) @@ -223,14 +233,16 @@ else: query_params = Eq(catalog['oid'], sequence.get_full_oid(query)) negotiator = get_utility(INegotiator) - for lang in {self.request.registry.settings.get('pyramid.default_locale_name', 'en'), + for lang in {self.request.registry.settings.get('pyramid.default_locale_name', + 'en'), self.request.locale_name, negotiator.server_language} | negotiator.offered_languages: index_name = 'title:{0}'.format(lang) if index_name in catalog: index = catalog[index_name] if index.check_query(query): - query_params |= Contains(index, ' and '.join((w+'*' for w in query.split()))) + query_params |= Contains(index, ' and '.join( + (w + '*' for w in query.split()))) params &= query_params if data.get('owner'): params &= Eq(catalog['role:owner'], data['owner']) @@ -245,6 +257,9 @@ if data.get('tags'): tags = [intids.register(term) for term in data['tags']] params &= Any(catalog['tags'], tags) + if data.get('collections'): + tags = [intids.register(term) for term in data['collections']] + params &= Any(catalog['collections'], tags) return unique(map(get_last_version, CatalogResultSet(CatalogQuery(catalog).query(params, sort_index='modified_date', diff -r ed31bfceddda -r 8184dadefc8b src/pyams_content/root/zmi/templates/advanced-search.pt --- a/src/pyams_content/root/zmi/templates/advanced-search.pt Wed Jul 01 18:05:38 2020 +0200 +++ b/src/pyams_content/root/zmi/templates/advanced-search.pt Fri Jul 03 12:27:49 2020 +0200 @@ -184,6 +184,13 @@ +
+ Collections +
+ +
+