[CMF-checkins] CVS: CMF/CMFTopic - DateCriteria.py:1.5

Tres Seaver tseaver@zope.com
Tue, 2 Jul 2002 19:12:51 -0400


Update of /cvs-repository/CMF/CMFTopic
In directory cvs.zope.org:/tmp/cvs-serv8233/CMFTopic

Modified Files:
	DateCriteria.py 
Log Message:


  - Enabled "within day" queries for FriendlyDateCriteria E.g.,
    field="modified", value="Now", operation="within_day",
    daterange="old" -> content which was modified "today".
    (Tracker # 474).


=== CMF/CMFTopic/DateCriteria.py 1.4 => 1.5 ===
     _editableAttributes = ( 'value', 'operation', 'daterange' )
 
-    _defaultDateOptions = ( (     1, '1 Day'    )
+    _defaultDateOptions = ( (     0, 'Now'      )
+                          , (     1, '1 Day'    )
                           , (     2, '2 Days'   )
                           , (     5, '5 Days'   )
                           , (     7, '1 Week'   )
@@ -94,10 +95,10 @@
             except:
                 raise ValueError, 'Supplied value should be an int'
 
-        if operation in ( 'min','max' ):
+        if operation in ( 'min', 'max', 'within_day' ):
             self.operation = operation
         else:
-            raise ValueError, 'Operation type not in set {min,max}'
+            raise ValueError, 'Operation type not in set {min,max,within_day}'
 
         if daterange in ( 'old', 'ahead' ):
             self.daterange = daterange
@@ -122,11 +123,23 @@
 
             date = DateTime() + value
 
-            result.append( ( field, date ) )
+            operation = self.operation
+            if operation == 'within_day':
 
-            result.append( ( '%s_usage' % field
-                           , 'range:%s' % self.operation
-                           ) )
+                range = ( date.earliestTime(), date.latestTime() )
+                result.append( ( field, range ) )
+
+
+                result.append( ( '%s_usage' % field
+                               , 'range:min:max'
+                               ) )
+            else:
+                result.append( ( field, date ) )
+
+
+                result.append( ( '%s_usage' % field
+                            , 'range:%s' % self.operation
+                            ) )
 
         return result