[CMF-checkins] CVS: Products/CMFCore - CatalogTool.py:1.42.2.4
Florent Guillaume
fg at nuxeo.com
Tue Nov 16 16:52:37 EST 2004
Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv22645
Modified Files:
Tag: CMF-1_4-branch
CatalogTool.py
Log Message:
Collector #120: Take into account query restrictions on 'effective' or
'expires' attributes during a search.
=== Products/CMFCore/CatalogTool.py 1.42.2.3 => 1.42.2.4 ===
--- Products/CMFCore/CatalogTool.py:1.42.2.3 Fri Apr 23 17:11:33 2004
+++ Products/CMFCore/CatalogTool.py Tue Nov 16 16:52:06 2004
@@ -18,6 +18,7 @@
from Products.ZCatalog.ZCatalog import ZCatalog
from Globals import InitializeClass, package_home, DTMLFile
from DateTime import DateTime
+from types import TupleType, ListType
from AccessControl.PermissionRole import rolesForPermissionOn
from AccessControl import ClassSecurityInfo
from utils import _checkPermission
@@ -194,6 +195,18 @@
result.append( 'user:%s' % user.getId() )
return result
+ def _convertQuery(self, kw):
+ # Convert query to modern syntax
+ for k in 'effective', 'expires':
+ kusage = k+'_usage'
+ if not kw.has_key(kusage):
+ continue
+ usage = kw[kusage]
+ if not usage.startswith('range:'):
+ raise ValueError("Incorrect usage %s" % `usage`)
+ kw[k] = {'query': kw[k], 'range': usage[6:]}
+ del kw[kusage]
+
# searchResults has inherited security assertions.
def searchResults(self, REQUEST=None, **kw):
"""
@@ -206,13 +219,49 @@
if not _checkPermission( AccessInactivePortalContent, self ):
base = aq_base( self )
now = DateTime()
- if hasattr( base, 'addIndex' ): # Zope 2.4 and above
- kw[ 'effective' ] = { 'query' : now, 'range' : 'max' }
- kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
- else: # Zope 2.3
- kw[ 'effective' ] = kw[ 'expires' ] = now
- kw[ 'effective_usage'] = 'range:max'
- kw[ 'expires_usage' ] = 'range:min'
+
+ self._convertQuery(kw)
+
+ # Intersect query restrictions with those implicit to the tool
+ for k in 'effective', 'expires':
+ if kw.has_key(k):
+ range = kw[k]['range'].split(':')
+ query = kw[k]['query']
+ if (not isinstance(query, TupleType) and
+ not isinstance(query, ListType)):
+ query = (query,)
+ else:
+ range = []
+ query = None
+ if 'min' in range:
+ lo = min(query)
+ else:
+ lo = None
+ if 'max' in range:
+ hi = max(query)
+ else:
+ hi = None
+ if k == 'effective':
+ if hi is None or hi > now:
+ hi = now
+ if lo is not None and hi < lo:
+ return ()
+ else: # 'expires':
+ if lo is None or lo < now:
+ lo = now
+ if hi is not None and hi < lo:
+ return ()
+ # Rebuild a query
+ if lo is None:
+ query = hi
+ range = 'max'
+ elif hi is None:
+ query = lo
+ range = 'min'
+ else:
+ query = (lo, hi)
+ range = 'min:max'
+ kw[k] = {'query': query, 'range': range}
return apply(ZCatalog.searchResults, (self, REQUEST), kw)
More information about the CMF-checkins
mailing list