Back to index

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

List of all members.

Public Member Functions

def __init__
def __get__
def __set__

Private Attributes

 _name
 _get_transform
 _set_transform

Detailed Description

A version of the field property type which is able to acquire
tools. This uses a not-very-nice acquisition hack, and is not 
generalisable to all acquisition-dependent operations, but should work
for tools in the portal root.

    >>> from Products.Archetypes.atapi import *
    >>> class MyContent(BaseContent):
    ...     portal_type = meta_type = 'MyContent'
    ...     schema = Schema((
    ...         ReferenceField('some_field', multiValued=True, 
    ...                        relationship='foo', storage=AnnotationStorage()),
    ...         ))
    ...
    ...     some_field = ATToolDependentFieldProperty('some_field')
    
    >>> registerType(MyContent, 'Archetypes')

    >>> self.portal._setOb('foo', MyContent('foo'))
    >>> foo = getattr(self.portal, 'foo')

These lines would fail with AttributeError: reference_catalog if it used 
the standard accessor.

    >>> foo.some_field
    []
    >>> foo.some_field = [self.folder.UID()]
    >>> foo.some_field
    [<ATFolder at /plone/Members/test_user_1_>]

Definition at line 114 of file fieldproperty.py.


Constructor & Destructor Documentation

def Archetypes.fieldproperty.ATToolDependentFieldProperty.__init__ (   self,
  name,
  get_transform = None,
  set_transform = None 
)

Reimplemented from Archetypes.fieldproperty.ATFieldProperty.

Definition at line 145 of file fieldproperty.py.

00145 
00146     def __init__(self, name, get_transform=None, set_transform=None):
00147         self._name = name
00148         self._get_transform = get_transform
00149         self._set_transform = set_transform
        

Here is the caller graph for this function:


Member Function Documentation

Reimplemented from Archetypes.fieldproperty.ATFieldProperty.

Definition at line 150 of file fieldproperty.py.

00150 
00151     def __get__(self, inst, klass):
00152         if inst is None:
00153             return self
00154         field = inst.getField(self._name)
00155         if field is None:
00156             raise KeyError("Cannot find field with name %s" % self._name)
00157         value = field.get(inst.__of__(getSite()))
00158         if self._get_transform is not None:
00159             value = self._get_transform(value)
00160         return value

Reimplemented from Archetypes.fieldproperty.ATFieldProperty.

Definition at line 161 of file fieldproperty.py.

00161 
00162     def __set__(self, inst, value):
00163         field = inst.getField(self._name)
00164         if field is None:
00165             raise KeyError("Cannot find field with name %s" % self._name)
00166         if self._set_transform is not None:
00167             value = self._set_transform(value)
00168         field.set(inst.__of__(getSite()), value)
        

Member Data Documentation

Reimplemented from Archetypes.fieldproperty.ATFieldProperty.

Definition at line 147 of file fieldproperty.py.

Reimplemented from Archetypes.fieldproperty.ATFieldProperty.

Definition at line 146 of file fieldproperty.py.

Reimplemented from Archetypes.fieldproperty.ATFieldProperty.

Definition at line 148 of file fieldproperty.py.


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