[Zope-CMF] LazyFilter and Effective Dates

seb bacon subscriptions@jamkit.com
Mon, 10 Jun 2002 00:13:12 +0100


Carl Rendell wrote:
> In sort, this allows me to obtain objects from a folder regardless of 
> those objects being cataloged, yet still have the filters provided by 
> 'searchContents()'. Folders for example are NOT cataloged so a catalog 
> search would not work for that case.
> 
> If anyone things this is completely out of wack, on the wrong tack, or 
> something else... Please let me know.

You're on the right tack, have you got it working yet?

> BTW: it took a lot of digging to find the bits needed for this, should 
> it be an example on zopelabs or a how to?

Both if you have time :)  Personally, I can't think of any circumstances 
where you wouldn't want this to be the default behaviour of 
objectValues.  I'd even suggest putting it into the CMF, but it may 
break things for existing applications (though again, I can't imagine 
how..?)

seb

> ## Script (Python) "filterObjectValues.py $Revision: 1.0 $"
> ##parameters=values=None
> ##title=Filter objectValues by effectivity and expiration date
> ##
> from ZTUtils import LazyFilter
> from AccessControl import getSecurityManager
> checkPermission=getSecurityManager().checkPermission
> items = []
> raw_items = context.objectValues(values)
> secure_items = LazyFilter( raw_items, skip='' )
> for item in secure_items:
>     if item.Type != 'Folder':
>         if not checkPermission('Access Inactive Content', context):
>             if item.effective() <= context.ZopeTime() and \
>                  item.expires() > context.ZopeTime():
>                   items.append(item)
>         else:
>             items.append(item)
> return items
> 
> On Monday, June 3, 2002, at 10:40  AM, Carl Rendell wrote:
> 
>> I have to received any 'bites' on this question yet, so I've been 
>> digging around myself to see if I could come up with a solution. So 
>> far I've been able to get 90% of the results I want by using the 
>> following script -
>>
>> ## Script (Python) "filterObjectValues.py $Revision: 1.0 $"
>> ##parameters=values=None
>> ##title=Filter objects by effectivity
>> ##
>> from ZTUtils import LazyFilter
>> items = []
>> raw_items = context.objectValues(values)
>> secure_items = LazyFilter( raw_items, skip='' )
>> for item in secure_items:
>>     if item.meta_type != 'Portal Folder':
>>         if item.effective() <= context.ZopeTime() and \
>>              item.expires() > context.ZopeTime():
>>               items.append(item)
>>     else:
>>         items.append(item)
>> return items
>>
>> This is used in a tal:define -
>>
>> <span tal:define="items python:here.filterObjectValues();">
>>
>> I found I needed to call LazyFilter first to take care of filtering 
>> access to un-published or protected items, and then apply the filter 
>> for effectivity and expiration.
>>
>> This works except items I'd like to ignore the effectivity test, or 
>> make it more sophisticated, so that 'authorized users' can see future 
>> effective or items. I'll continue to filter on expires as there is no 
>> need to view them in the editing context the user is in.
>>
>> So.. anyone care to help me understand how to check security in this 
>> context? Also, is this the right track, or have I missed something 
>> completely obvious?
>>
>> ~C
>>
>>>
>>> When using the CatalogTool - portal_catalog.searchResults() - both
>>> security AND effectivity are taken into account. However, when
>>> rendering contents from a folder via objectValues or objectItems
>>> one can use LazyFilter to take care of security and workflow
>>> (published or un-published), but there is no provision for
>>> effectivity.
>>>
>>> I'd prefer to have something that works like LazyFilter but also
>>> performs the effectivity checks like searchResults as I would cull
>>> the results down much faster. Has anyone gone down this path
>>> before? Am I just missing something in the capabilities of
>>> LazyFolder?
>>>
>>> Just looking for a crumb or set of crumbs to follow so I don't
>>> re-invent the wheel.
>>>
> 
> Carl E. Rendell
> Solution43
> Information Distribution Consulting        |   "Ahhhh the power of
> cer@sol43.com                              |    acquisition"  - Chef Z
> 
>>
> 
> 
> 
> _______________________________________________
> Zope-CMF maillist  -  Zope-CMF@zope.org
> http://lists.zope.org/mailman/listinfo/zope-cmf
> 
> See http://www.zope.org/Products/PTK/Tracker for bug reports and feature 
> requests