문제

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'
도움이 되었습니까?

해결책

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.

다른 팁

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'.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top