В Пнд, 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. 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... Regards, Ruslan _______________________________________________ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com