Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
CMFTopic.DateCriteria.FriendlyDateCriterion Class Reference
Inheritance diagram for CMFTopic.DateCriteria.FriendlyDateCriterion:
Inheritance graph
[legend]
Collaboration diagram for CMFTopic.DateCriteria.FriendlyDateCriterion:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def defaultDateOptions
def getEditForm
def edit
def getCriteriaItems

Public Attributes

 id
 field
 value
 operation
 daterange

Static Public Attributes

string meta_type = 'Friendly Date Criterion'
tuple security = ClassSecurityInfo()

Static Private Attributes

 __implements__ = z2ICriterion
tuple _editableAttributes = ( 'value', 'operation', 'daterange' )
tuple _defaultDateOptions

Detailed Description

    Put a friendly interface on date range searches, like
    'where effective date is less than 5 days old'.

Definition at line 32 of file DateCriteria.py.


Constructor & Destructor Documentation

def CMFTopic.DateCriteria.FriendlyDateCriterion.__init__ (   self,
  id,
  field 
)

Definition at line 61 of file DateCriteria.py.

00061 
00062     def __init__( self, id, field ):
00063 
00064         self.id = id
00065         self.field = field
00066         self.value = None
00067         self.operation = 'min'
00068         self.daterange = 'old'


Member Function Documentation

    Return a list of default values and labels for date options.

Definition at line 70 of file DateCriteria.py.

00070 
00071     def defaultDateOptions( self ):
00072         """
00073             Return a list of default values and labels for date options.
00074         """
00075         return self._defaultDateOptions

def CMFTopic.DateCriteria.FriendlyDateCriterion.edit (   self,
  value = None,
  operation = 'min',
  daterange = 'old' 
)
    Update the values to match against.

Definition at line 89 of file DateCriteria.py.

00089 
00090             ):
00091         """
00092             Update the values to match against.
00093         """
00094         if value in ( None, '' ):
00095             self.value = None
00096         else:
00097             try:
00098                 self.value = int( value )
00099             except:
00100                 raise ValueError, 'Supplied value should be an int'
00101 
00102         if operation in ( 'min', 'max', 'within_day' ):
00103             self.operation = operation
00104         else:
00105             raise ValueError, 'Operation type not in set {min,max,within_day}'
00106 
00107         if daterange in ( 'old', 'ahead' ):
00108             self.daterange = daterange
00109         else:
00110             raise ValueError, 'Date range not in set {old,ahead}'

Here is the caller graph for this function:

    Return a sequence of items to be used to build the catalog query.

Definition at line 112 of file DateCriteria.py.

00112 
00113     def getCriteriaItems( self ):
00114         """
00115             Return a sequence of items to be used to build the catalog query.
00116         """
00117         if self.value is not None:
00118             field = self.Field()
00119             value = self.value
00120             operation = self.operation
00121 
00122             # Negate the value for 'old' days
00123             if self.daterange == 'old' and value != 0:
00124                 value = -value
00125 
00126                 # Also reverse the operator to match what a user would expect.
00127                 # Queries such as "More than 2 days ago" should match dates
00128                 # *earlier* than "today minus 2", and "Less than 2 days ago"
00129                 # would be expected to return dates *later* then "today minus
00130                 # two".
00131                 if operation == 'max':
00132                     operation = 'min'
00133                 elif operation == 'min':
00134                     operation = 'max'
00135 
00136             now = _as_of()
00137             date = now + value
00138 
00139             if operation == 'within_day':
00140                 # When items within a day are requested, the range is between
00141                 # the earliest and latest time of that particular day
00142                 range = ( date.earliestTime(), date.latestTime() )
00143                 return ( ( field, {'query': range, 'range': 'min:max'} ), )
00144 
00145             elif operation == 'min':
00146                 if value != 0:
00147                     if self.daterange == 'old':
00148                         date_range = (date, now)
00149                         return ( ( field, { 'query': date_range
00150                                           , 'range': 'min:max'
00151                                           } ), )
00152                     else:
00153                         return ( ( field, { 'query': date.earliestTime()
00154                                           , 'range': operation
00155                                           } ), )
00156                 else:
00157                     # Value 0 means "Now", so get everything from now on
00158                     return ( ( field, {'query': date,'range': operation } ), )
00159 
00160             elif operation == 'max':
00161                 if value != 0:
00162                     if self.daterange == 'old':
00163                         return ((field, {'query': date, 'range': operation}),)
00164                     else:
00165                         date_range = (now, date.latestTime())
00166                         return ( ( field, { 'query': date_range
00167                                           , 'range': 'min:max'
00168                                           } ), )
00169                 else:
00170                     # Value is 0, meaning "Now", get everything before "Now"
00171                     return ( ( field, {'query': date, 'range': operation} ), )
00172         else:
00173             return ()
00174 
00175 InitializeClass(FriendlyDateCriterion)
00176 
00177 
00178 # Register as a criteria type with the Topic class
00179 Topic._criteriaTypes.append( FriendlyDateCriterion )

Here is the call graph for this function:

    Return the name of the skin method used by Topic to edit
    criteria of this type.

Definition at line 77 of file DateCriteria.py.

00077 
00078     def getEditForm( self ):
00079         """
00080             Return the name of the skin method used by Topic to edit
00081             criteria of this type.
00082         """
00083         return 'friendlydatec_editform'

Here is the call graph for this function:


Member Data Documentation

Definition at line 40 of file DateCriteria.py.

Initial value:
( (     0, 'Now'      )
                          , (     1, '1 Day'    )
                          , (     2, '2 Days'   )
                          , (     5, '5 Days'   )
                          , (     7, '1 Week'   )
                          , (    14, '2 Weeks'  )
                          , (    31, '1 Month'  )
                          , (  31*3, '3 Months' )
                          , (  31*6, '6 Months' )
                          , (   365, '1 Year'   )
                          , ( 365*2, '2 years'  )
                          )

Definition at line 48 of file DateCriteria.py.

Definition at line 46 of file DateCriteria.py.

Definition at line 67 of file DateCriteria.py.

Definition at line 64 of file DateCriteria.py.

Definition at line 63 of file DateCriteria.py.

string CMFTopic.DateCriteria.FriendlyDateCriterion.meta_type = 'Friendly Date Criterion' [static]

Definition at line 42 of file DateCriteria.py.

Definition at line 66 of file DateCriteria.py.

tuple CMFTopic.DateCriteria.FriendlyDateCriterion.security = ClassSecurityInfo() [static]

Definition at line 44 of file DateCriteria.py.

Definition at line 65 of file DateCriteria.py.


The documentation for this class was generated from the following file: