[CMF-checkins] CVS: Products/CMFCore - CatalogTool.py:1.55.2.1

Florent Guillaume fg at nuxeo.com
Tue Nov 16 17:03:33 EST 2004


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv25488/CMFCore

Modified Files:
      Tag: CMF-1_5-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.55 => 1.55.2.1 ===
--- Products/CMFCore/CatalogTool.py:1.55	Thu Aug 12 11:07:39 2004
+++ Products/CMFCore/CatalogTool.py	Tue Nov 16 17:03:02 2004
@@ -15,6 +15,7 @@
 $Id$
 """
 
+from types import TupleType, ListType
 from AccessControl import ClassSecurityInfo
 from AccessControl.PermissionRole import rolesForPermissionOn
 from DateTime import DateTime
@@ -185,6 +186,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):
         """
@@ -196,8 +209,49 @@
 
         if not _checkPermission( AccessInactivePortalContent, self ):
             now = DateTime()
-            kw['effective'] = {'query': now, 'range': 'max'}
-            kw['expires'] = {'query': now, '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 ZCatalog.searchResults(self, REQUEST, **kw)
 



More information about the CMF-checkins mailing list