[Zope3-Users] Adapters and getters and setters
darryl at darrylcousins.net.nz
Mon Jul 24 17:01:32 EDT 2006
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):
... 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?
More information about the Zope3-users