Back to index

plone3  3.1.7
Public Member Functions | Private Attributes
CMFDefault.formlib.schema.ProxyFieldProperty Class Reference

List of all members.

Public Member Functions

def __init__
def __get__
def __set__
def __getattr__

Private Attributes

 _field
 _get_name
 _set_name

Detailed Description

Computed attributes based on schema fields.

Based on zope.schema.fieldproperty.FieldProperty.

Definition at line 43 of file schema.py.


Constructor & Destructor Documentation

def CMFDefault.formlib.schema.ProxyFieldProperty.__init__ (   self,
  field,
  get_name = None,
  set_name = None 
)

Definition at line 50 of file schema.py.

00050 
00051     def __init__(self, field, get_name=None, set_name=None):
00052         if get_name is None:
00053             get_name = field.__name__
00054 
00055         self._field = field
00056         self._get_name = get_name
00057         self._set_name = set_name


Member Function Documentation

def CMFDefault.formlib.schema.ProxyFieldProperty.__get__ (   self,
  inst,
  klass 
)

Definition at line 58 of file schema.py.

00058 
00059     def __get__(self, inst, klass):
00060         if inst is None:
00061             return self
00062 
00063         attribute = getattr(inst.context, self._get_name, _marker)
00064         if attribute is _marker:
00065             field = self._field.bind(inst)
00066             attribute = getattr(field, 'default', _marker)
00067             if attribute is _marker:
00068                 raise AttributeError(self._field.__name__)
00069         elif isinstance(attribute, Pdata):
00070             attribute = str(attribute)
00071         elif callable(attribute):
00072             attribute = attribute()
00073 
00074         if self._field._type == str:
00075             return attribute
00076         if isinstance(attribute, str) and inst.encoding:
00077             return attribute.decode(inst.encoding)
00078         if isinstance(attribute, DateTime):
00079             return parseDatetimetz(attribute.ISO8601())
00080         if isinstance(attribute, (tuple, list)):
00081             if inst.encoding:
00082                 attribute = [ isinstance(v, str)
00083                               and v.decode(inst.encoding) or v
00084                               for v in attribute ]
00085             if self._field._type == list:
00086                 return attribute
00087             if self._field._type == tuple:
00088                 return tuple(attribute)
00089             return set(attribute)
00090         return attribute

Definition at line 114 of file schema.py.

00114 
00115     def __getattr__(self, name):
00116         return getattr(self._field, name)
00117 

Here is the caller graph for this function:

def CMFDefault.formlib.schema.ProxyFieldProperty.__set__ (   self,
  inst,
  value 
)

Definition at line 91 of file schema.py.

00091 
00092     def __set__(self, inst, value):
00093         field = self._field.bind(inst)
00094         field.validate(value)
00095         if field.readonly:
00096             raise ValueError(self._field.__name__, 'field is readonly')
00097         if isinstance(value, unicode) and inst.encoding:
00098             value = value.encode(inst.encoding)
00099         elif isinstance(value, datetime):
00100             value = DateTime(value.isoformat())
00101         elif isinstance(value, (set, tuple, list)):
00102             if inst.encoding:
00103                 value = [ isinstance(v, unicode)
00104                           and v.encode(inst.encoding) or v
00105                           for v in value ]
00106             if not self._field._type == list:
00107                 value = tuple(value)
00108         if self._set_name:
00109             getattr(inst.context, self._set_name)(value)
00110         elif inst.context.hasProperty(self._get_name):
00111             inst.context._updateProperty(self._get_name, value)
00112         else:
00113             setattr(inst.context, self._get_name, value)


Member Data Documentation

Definition at line 54 of file schema.py.

Definition at line 55 of file schema.py.

Definition at line 56 of file schema.py.


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