Question

There is a way to hide a specific object of my catalog results? I have a configuration file that I don't want to show. I'm filtering by id, but it seems so ugly.

from Products.CMFCore.utils import getToolByName
def search(context):
    catalog = getToolByName(context, 'portal_catalog')
    items = catalog()
    for item in items:
        if item.id != "config_file":
            'do something'
Was it helpful?

Solution

If you are already hiding the object from the navigation tree, you can filter on the same property by testing for exclude_from_nav:

items = catalog()
for item in items:
    if item.exclude_from_nav:
        continue

    # do something with all objects *not* excluded from navigation.

It is harder to filter out things that don't match a criteria. Using a test on the brain object like the above is a perfectly fine way to remove a small subset from your result set.

If you need handle a larger percentage of 'exceptions' you'll need to rethink your architecture, perhaps.

OTHER TIPS

With Products.AdvancedQuery you can create advanced queries and filtering on catalog results. See also this how to.

In the general case, setting a content item's expiration date to some past date hides it from search results (so long as the user does not have the Access inactive portal content permission).

It's an easy way to hide pieces of content that should be visible to all, but that you don't want cluttering up search results e.g. a Document that serves as the homepage.

I always use 1st Jan 2001 as the date so I can easily recognise when I've used this little 'hack'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top