[Zope3-Users] Adapters and getters and setters

Darryl Cousins darryl at darrylcousins.net.nz
Mon Jul 24 17:01:32 EDT 2006


Hi All,

I only recently began using formlib and I have used a schema to describe
the form, and provided an adapter to adapt the object to the schema.

It seems that formlib uses the adapter to access and set attributes on
the object. To allow it to do that I need to provide getters and setters
for the adapter to access the attributes on the object itself:

    >>> class MyAdapterForMyObject(object):
    ...     implements(IMyAdapter)
    ...     def __init__(self, context):
    ...         self.context = context
    ...     def title():
    ...         def fget(self):
    ...             return self.context.title
    ...         def fset(self, value):
    ...             self.context.title = value
    ...         return locals()
    ...     title = property(**title())

Before using formlib I would usually have a getContext() method on the
adapter to return the adapted object and manually get or set the
attributes (in the update method for example). Doing the above means I
don't need to.

Am I going about this the right way?

Best regards,
Darryl Cousins



More information about the Zope3-users mailing list