[Zope3-dev] Re: __name__ in auto generated addforms
Florian Lindner
mailinglists at xgm.de
Mon May 30 15:54:30 EDT 2005
Hey!
Sorry for mailing you again. Have you found any better solution where I can
omit I name chooser? You said that I eventually don't it.
Thanks a lot,
Florian
Am Montag, 23. Mai 2005 22:19 schrieb Ruslan Spivak:
> В Пнд, 23/05/2005 в 22:02 +0200, Florian Lindner пишет:
> > Am Sonntag, 22. Mai 2005 01:31 schrieb Ruslan Spivak:
> > > В Сбт, 21/05/2005 в 19:33 +0200, Florian Lindner пишет:
> > > > Hello,
> > > > is it possible to let the user enter the name of a object (the
> > > > __name__ attribut) in forms that are auto generated from schema data
> > > > (via the addform directive)?
> > > >
> > > > Thanks,
> > > >
> > > > Florian
> > >
> > > Hi, Florian.
> > >
> > > You need create adapter to zope.app.container.interfaces.INameChooser
> > > and register it for your xxx interface.
> > >
> > > Take a look at bugtracker application inside zope, it contains example
> > > of INameChooser usage.
> >
> > Ok, I've done so.
> >
> > I've created a INameChooser implementation:
> >
> >
> > from zope.app.container.interfaces import INameChooser
> >
> > class NameChooser:
> > implements(INameChooser)
> >
> > def __init__(self, context):
> > self.context = context
> >
> > def chooseName(self, name, object):
> > print object
> > return object.title
> >
> > gives the traceback:
> >
> > 2005-05-23T22:01:13 ERROR SiteError
> > http://localhost:8080/cs/home/zope.manager/t
> > estfolder/+/AddCSLink.html%3D
> > Traceback (most recent call last):
> >
> > File
> > "/home/florian/Desktop/zope/lib/python/CS/ContentFolder/contentfolder.py"
> > , line 22, in
> > chooseName
> > return object.title
> > AttributeError: 'Link' object has no attribute 'title'
> >
> > but the Link object has a attribute title.
> >
> > title = TextLine(
> > title = u"Title",
> > description = u"Short title",
> > required = True
> > )
> >
> > What is wrong there?
>
> You need to use set_before_add in your addform definition to set needed
> fields which will be assigned to newly created object before it's added
> (take a look at ZCML online help, browser section). That's needed if you
> want to access fields of object's schema inside INameChooser
> implementation.
I'll have a look at it tomorrow...
> P.S. As you probably noted INameChooser is helpful, for example, for
> creating custom object names that follow your own policy(let's say you
> want prepend year_month_day to object's title or whatever you want to
> do). I just reread your first post and wondering if i'm correctly
> understood your question and you really need INameChooser...
What I need is fairly simple: If I auto-create a addform the user sees widgets
for all schema fields I've created in my interface. But I couldn't set the
name of the object (__name__ attribute).
I've just discovered that this is not entirely true.
If I click on menu items I've created with:
<addform
title="Link"
name="AddCSLink.html"
schema="CS.Link.interfaces.ILink"
content_factory="CS.Link.link.Link"
permission="zope.Public"
layer="centershock"
menu="CSaddMenu"
for="CS.ContentFolder.interfaces.IContentFolder"
/>
I get this URL as a link
http://localhost:8080/++skin++centershock/cs/home/zope.manager/%40%40AddCSLink.html
where I can't enter the objects name.
But when I take the URL from the ZMI add dialoge and add a ++skin++centershock
I get this URL:
http://localhost:8080/++skin++centershock/cs/home/zope.manager/+/AddCSLink.html=
Both refer to the same object and both look the same with the only difference
that I can enter a objects name in the last one.
You know what the difference is and why is it?
Thanks,
Florian
More information about the Zope3-dev
mailing list