[Zope-CMF] LazyFilter and Effective Dates

Carl Rendell cer@sol43.com
Mon, 3 Jun 2002 22:11:15 -0700


Still no bites yet, but I've been closing in on the script and have 
added what appears to function as the check for users to view 
'inactive content'. I've yet to complete testing, but the following 
appears to function like portal_catalog.searchContents() from a 
filter perspective but works with objectValues - and possibly 
objectItems -

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.

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?

## 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
>