[Zope3-Users] property in view/adapter

2005-05-10 Thread Marc Rijken
Hi Everybody,
I have an adapter Person to Object. Some code:
class Object:
def __init__(self):
self.attributes = {}
class NamedObject:
def __init__(self, context):
self.context = context
def getName(self, type):
return self.context.attributes[type]
def setName(self, type, value):
self.context.attributes[type] = value
def nameProperty(type):
fget = lambda self: self.getName(type)
fset = lambda self, value: self.setName(type, value)
return property(fget, fset)
class Person(NamedObject):
firstname = nameProperty('firstname')
When I try in a view on an Object adapted to Person, the following:
self.context.firstname = 'Marc'
the name will *not* be set and I get no single error. When I call
self.context.setName('firstname', 'Marc')
the name will be set.
The getter (x=self.context.firstname) is functioning without any problems.
It looks like property can not be used as setter in views/adapters. Is 
that the problem? Or is there an other problem?

Marc
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Using metadata and __name__ in addform

2005-05-10 Thread Fred Drake
On 5/10/05, Florian Lindner <[EMAIL PROTECTED]> wrote:
> how can I automatically create a addform that allows the user to enter the
> metadate zope:description and the __name__. Using addform->fields has not
> worked.

There are a couple of ways.

1.  Use a custom class and template.  This isn't so hard, but makes it
harder to change the schema at a later time (since the form has to be
changed).

2.  Add a field to the schema that provide the specific metadata field
you want, and create a specialized Dublin Core adapter.  Then the
field from the schema is just another field, and you don't have to use
a custom class and template.

Luckily for you, I just made the later easier on the Zope 3 trunk last
night.  :-)  See src/zope/app/dublincore/partial.txt for more
information on how to do this.


  -Fred

-- 
Fred L. Drake, Jr.
Zope Corporation
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Using metadata and __name__ in addform

2005-05-10 Thread Florian Lindner
Hello,
how can I automatically create a addform that allows the user to enter the 
metadate zope:description and the __name__. Using addform->fields has not 
worked.

Thanks,
Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users