On Aug 22, 2005, at 11:36 AM, Markus Leist wrote:

Hi all,

I have build an List of Choices and it works well:
in interface:
    hostlist = List(
        title=_(u"Host List"),
        description=_(u"Host List"),
        value_type = Choice(
            required = True,
            vocabulary = "IkGroupHosts"),

def HostsVocabulary(context):
    dynHostList = []
    for (oid, oobj) in iid.items():
        if IIkHost.providedBy(oobj.object):
dynHostList.append( SimpleTerm( oobj.object.getIkTitle (), oobj.object.getIkTitle()))
    return SimpleVocabulary( dynHostList)

object has string-result:
hostlist      [u'titan', u'radon']

now i want to store references in (my new) lIst  by vocabulary:

def HostsVocabulary(context):
    dynHostList = []
    iid = zapi.getUtility( IIntIds, 'iid')
    for (oid, oobj) in iid.items():
        if IIkHost.providedBy(oobj.object):
dynHostList.append( SimpleTerm( KeyReferenceToPersistent (oobj.object), oobj.object.getIkTitle()))
    return SimpleVocabulary( dynHostList)

Two things about this, based on a very quick look.

First, be aware that walking all of the intids for this is probably pretty inefficient for the long haul, unless your app has a very, very limited scope. Maybe this is a prototype, though, so that's cool.

Second, why are you using the key reference as the term value? Is it necessary? Using the actual values should be more likely to give you what you want. Because you are using, *the key references* are the value being stored in your lists, not the actual objects.

when commit the form:
File "/opt/ikom/Zope3/src/zope/schema/_bootstrapfields.py", line 133, in validate
    if value == self.missing_value:
File "/opt/ikom/Zope3/src/zope/app/keyreference/persistent.py", line 56, in __cmp__
    if self.key_type_id == other.key_type_id:
AttributeError: 'NoneType' object has no attribute 'key_type_id'

Right, so this is saying that the keyreference __cmp__ code expects to only ever be compared with another keyreference, not None. This could be changed, I suppose, if you actually intend to be storing the keyreference. But I suggest the right thing to do for you is to just use the actual value in the term.

Zope3-users mailing list

Reply via email to