Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
Archetypes.fieldproperty.ATDateTimeFieldProperty Class Reference
Inheritance diagram for Archetypes.fieldproperty.ATDateTimeFieldProperty:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.fieldproperty.ATDateTimeFieldProperty:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __get__
def __set__

Private Member Functions

def _zope2python_dt
def _python2zope_dt

Detailed Description

A field property for DateTime fields. This takes care of converting
to and from a Python datetime.

    >>> from Products.Archetypes.atapi import *
    >>> class MyContent(BaseObject):
    ...     portal_type = meta_type = 'MyContent'
    ...     schema = Schema((
    ...         DateTimeField('date_field', storage=AnnotationStorage()),
    ...         ))
    ...
    ...     date_field = ATDateTimeFieldProperty('date_field')
    
    >>> registerType(MyContent, 'Archetypes')

We can now get and set date/times.

    >>> from datetime import datetime
    >>> target_date = datetime(2007, 4, 9, 12, 3, 12)
    
    >>> foo = MyContent('foo')
    >>> foo.date_field = target_date
    >>> foo.date_field
    datetime.datetime(2007, 4, 9, 12, 3, 12, ...)
    
    >>> foo.getDate_field().ISO()
    '2007-04-09 12:03:12'
    
    >>> foo.setDate_field(DateTime('2007-04-10 13:11:01'))
    >>> foo.date_field
    datetime.datetime(2007, 4, 10, 13, 11, 1, ...)

Definition at line 173 of file fieldproperty.py.


Constructor & Destructor Documentation

Definition at line 206 of file fieldproperty.py.

00206 
00207     def __init__(self, name):
00208         super(ATDateTimeFieldProperty, self).__init__(name, self._zope2python_dt, self._python2zope_dt)
        

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def Archetypes.fieldproperty.ATFieldProperty.__get__ (   self,
  inst,
  klass 
) [inherited]

Reimplemented in Archetypes.fieldproperty.ATToolDependentFieldProperty.

Definition at line 95 of file fieldproperty.py.

00095 
00096     def __get__(self, inst, klass):
00097         if inst is None:
00098             return self
00099         field = inst.getField(self._name)
00100         if field is None:
00101             raise KeyError("Cannot find field with name %s" % self._name)
00102         value = field.get(inst)
00103         if self._get_transform is not None:
00104             value = self._get_transform(value)
00105         return value

def Archetypes.fieldproperty.ATFieldProperty.__set__ (   self,
  inst,
  value 
) [inherited]

Reimplemented in Archetypes.fieldproperty.ATToolDependentFieldProperty.

Definition at line 106 of file fieldproperty.py.

00106 
00107     def __set__(self, inst, value):
00108         field = inst.getField(self._name)
00109         if field is None:
00110             raise KeyError("Cannot find field with name %s" % self._name)
00111         if self._set_transform is not None:
00112             value = self._set_transform(value)
00113         field.set(inst, value)
        
def Archetypes.fieldproperty.ATDateTimeFieldProperty._python2zope_dt (   self,
  python_dt 
) [private]

Definition at line 214 of file fieldproperty.py.

00214 
00215     def _python2zope_dt(self, python_dt):
00216         if python_dt is None:
00217             return None
        return DateTime(python_dt.isoformat())

Here is the caller graph for this function:

Definition at line 209 of file fieldproperty.py.

00209 
00210     def _zope2python_dt(self, zope_dt):
00211         if zope_dt is None:
00212             return None
00213         return parseDatetimetz(zope_dt.ISO8601())

Here is the caller graph for this function:


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