diff --git a/castle/cms/browser/controlpanel/configure.zcml b/castle/cms/browser/controlpanel/configure.zcml index ea17f9308..f4e138a25 100644 --- a/castle/cms/browser/controlpanel/configure.zcml +++ b/castle/cms/browser/controlpanel/configure.zcml @@ -142,7 +142,7 @@ +

View Title

+

Excluded content

This is a list of items with "Exclude From Search" selected in their properties. You can click on an item to navigate and edit that property if you'd like it to show up in search results.

${item/Title}

+

+

Exclude by type

+ Content can be excluded from searches by type. Adding to the list below will make all content of that type not show up in search results. +

+
+ +
- \ No newline at end of file + diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index d29dda147..204636a6e 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -1,4 +1,5 @@ from castle.cms.interfaces import ICrawlerConfiguration +from castle.cms.interfaces.controlpanel import ISearchExclusionSettings from castle.cms.utils import get_public_url from castle.cms.indexing import hps @@ -51,10 +52,18 @@ def options(self): } ] + registry = getUtility(IRegistry) + settings = registry.forInterface(ISearchExclusionSettings) + exclude_types_from_search = settings.exclude_from_searches + excluded_content = [] + + if exclude_types_from_search: + excluded_content = settings.items_to_exclude or [] + ptypes = api.portal.get_tool('portal_types') allow_anyway = ['Audio'] for type_id in ptypes.objectIds(): - if type_id in ('Link', 'Document', 'Folder'): + if type_id in excluded_content: continue _type = ptypes[type_id] if not _type.global_allow and type_id not in allow_anyway: @@ -68,7 +77,6 @@ def options(self): }) additional_sites = [] - registry = getUtility(IRegistry) settings = registry.forInterface(ICrawlerConfiguration, prefix='castle') if hps.is_enabled() and settings.crawler_active and settings.crawler_site_maps: result = hps.get_index_summary(hps.get_index_name(), dict(field="domain")) @@ -164,6 +172,9 @@ def __call__(self): query['has_private_parents'] = False query['exclude_from_search'] = False + allowed_types = self.get_allowed_types(query) + query['portal_type'] = allowed_types + try: page_size = int(self.request.form.get('pageSize')) except Exception: @@ -178,6 +189,26 @@ def __call__(self): return self.get_hps_results(page, page_size, query) else: return self.get_results(page, page_size, query) + + def get_allowed_types(self, query): + # If a filter tab is selected, use that portal type only + portal_types = query.get('portal_type') + if portal_types is not None: + return portal_types + + # Otherwise, use all non-excluded portal types + registry = getUtility(IRegistry) + settings = registry.forInterface(ISearchExclusionSettings) + exclude_types_from_search = settings.exclude_from_searches + excluded_content = [] + + if exclude_types_from_search: + excluded_content = settings.items_to_exclude or [] + + ptypes = api.portal.get_tool('portal_types') + allowed_types = [type for type in ptypes.objectIds() if type not in excluded_content] + + return tuple(allowed_types) def get_results(self, page, page_size, query): # regular plone search diff --git a/castle/cms/configure.zcml b/castle/cms/configure.zcml index bcd32a321..1e568211d 100644 --- a/castle/cms/configure.zcml +++ b/castle/cms/configure.zcml @@ -130,6 +130,10 @@ component=".vocabularies.ProvidesTitleSummaryLeadImageVocabularyFactory" name="castle.cms.vocabularies.ProvidesTitleSummaryLeadImage" /> + + + 3014 + diff --git a/castle/cms/profiles/3014/registry/registry.xml b/castle/cms/profiles/3014/registry/registry.xml new file mode 100644 index 000000000..335bc6b60 --- /dev/null +++ b/castle/cms/profiles/3014/registry/registry.xml @@ -0,0 +1,5 @@ + + + + diff --git a/castle/cms/upgrades.zcml b/castle/cms/upgrades.zcml index 48de65901..66778414e 100644 --- a/castle/cms/upgrades.zcml +++ b/castle/cms/upgrades.zcml @@ -37,7 +37,6 @@ profile="castle.cms:default" /> - + + + diff --git a/castle/cms/upgrades/__init__.py b/castle/cms/upgrades/__init__.py index ebb3f77b3..0e22891b3 100644 --- a/castle/cms/upgrades/__init__.py +++ b/castle/cms/upgrades/__init__.py @@ -137,3 +137,5 @@ def upgrade_3011(site, logger=CASTLE_LOGGER): upgrade_3012 = default_upgrade_factory('3012') + +upgrade_3014 = default_upgrade_factory('3014') diff --git a/castle/cms/vocabularies.py b/castle/cms/vocabularies.py index d2c2dadca..8779b9403 100644 --- a/castle/cms/vocabularies.py +++ b/castle/cms/vocabularies.py @@ -125,6 +125,23 @@ def __call__(self, context): LocationsVocabulary = LocationsVocabularyFactory() +@implementer(IVocabularyFactory) +class SiteTypesVocabularyFactory(object): + + def __call__(self, context): + site = getSite() + portal_types = getToolByName(site, "portal_types") + types = portal_types.listContentTypes() + terms = [] + for type in types: + terms.append(SimpleVocabulary.createTerm(type, type, type)) + + return SimpleVocabulary(terms) + + +SiteTypesVocabulary = SiteTypesVocabularyFactory() + + @implementer(IVocabularyFactory) class MimeTypeVocabularyFactory(object):