[Zope3-Users] set_before_add
mats.nordgren
mats at ronin-group.org
Fri Oct 14 10:44:30 EDT 2005
On Fri, 14 Oct 2005 16:36:45 +0200, gnotari wrote
> > On Fri, 14 Oct 2005 15:36:09 +0200, gnotari wrote
> > > I'm at loss:
> > >
> > > I'm replicating the example at cap. 14.3 of Philipp's (Worldcookery)
> > > book. It's all about auto-assigning names to object being added to
> > containers.
> > >
> > > After much tinkering, it does seem to me that this directive
> > >
> > > <browser:addform
> > > ...
> > > ...
> > > set_before_add="id"
> > > >
> > >
> > > is not working at all.
> > > I throughly checked my NameChooser derived class, and verified it
> > > works if I make it return some static "name".
> > >
> > > But if I set my NameChooser to use the new object's id attribute (as
> > > per example) and try to Add the object, I'm not asked for the "id"
> > > and immediately get the error "An empty name was provided. Names
> > > cannot be empty."
>
> > I just tried to have Zope auto assign the name of an object taking the
> > TextLine field 'title' as name. It worked just fine. Remember
> NameChooser
> > has to be implemented on the container, not the object. The
> set_before_add
> > should be added to the addform of the object itself.
> >
> > I wrote a small howto on NameChooser at http://counterfate.servebeer.com
> >
> > Replace the part in the chooseName function with:
> >
> > if not name:
> > name = object.id
> > return name
>
> Sorry, but it does not solve.
> I checked your code, and indeed I implemented the same way.
> Indeed, my code works if I make it generate arbitrary names.
>
> It just does not work if I try to name a new object after one of its
> attributes because:
> - the attribute value is not set at the time the object is created
> - I cannot have the add menu ask for it before actually adding (this
> is what set_before_add should be meant for, I suppose)
>
> Just for info, I'm using Zope 3.1.
>
> I'm open to any other suggestion as to how have my contained objects
> (books) be added with thei ISBN code as name in their container.
>
> thanks
> Guido
Guido,
Yes, I get the same when using 'id' as field name. If I specify a value of id
in my implementation,
Class SimpleObject(Persistent):
implements(ISimpleObject)
id = u'NewID'
...
it adds the object directly without giving me the addform. Not sure why it
does this. Sounds like this is a case for the gurus.
Sorry I can't be of more assistance.
gnosis
More information about the Zope3-users
mailing list