[Zope-CMF] RE: Finding all syndication enabled folders
Florent Guillaume
fg@nuxeo.com
Sat, 1 Jun 2002 17:44:48 +0000 (UTC)
<vsbabu@vsbabu.org> wrote:
> >> Never mind, it was a simple matter using portal_catalog.
> >> ##
> >> results = []
> >> for r in context.portal_catalog({'Type':['Folder']}):
> >> o = r.getObject()
> >> if 1==context.portal_syndication.isSyndicationAllowed(o):
> >> results.append(o)
> >> return results
> >> ##
> >
> ><teaching granny to suck eggs>
> >
> >If your Folders are already cataloged, it might be worth adding
> >'isSyndicationAllowed' to the catalog metadata, otherwise you're doing a
> >getObject on every Folder in your site, which is pretty expensive?
> >
> ></teaching granny to suck eggs>
>
> Right. isSyndicationAllowed is a method, so I'm not sure this can be added to the
> catalog. I'd say the fastest and least expensive method is to add this (or the
> equivalent property - need to find out what it is) to the catalog *index* and then
> search like
>
> return context.portal_catalog({'Type':['Folder'],'isSyndicationAllowed':1})
>
> to get a list of catalog records.
Except that isSyndicationAllowed is a method of portal_syndication,
not of the folder. So you have to add to the folder a new method that
does it. Here is an *untested* monkey-patch that does it:
from AccessControl.PermissionRole import PermissionRole
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.CMFCorePermissions import View
from Products.CMFCore.PortalFolder import PortalFolder
def isSyndicationAllowed(self):
"""Returns true if the syndication is allowed for this object."""
stool = getToolByName(self, 'portal_syndication', None)
if stool is None:
return 0
return stool.isSyndicationAllowed(self)
PortalFolder.isSyndicationAllowed = isSyndicationAllowed
PortalFolder.isSyndicationAllowed__roles__ = PermissionRole(View)
Then, as suggested, add a isSyndicationAllowed field index to the
catalog (and you'll probably have to query for equality with the
string '1', not the integer 1).
Florent
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com