[Zope3-Users] Re: Vocabulary

Vinny vinny-mail-01+zope3users at palaceofretention.ca
Thu Mar 8 21:29:14 EST 2007


On Sun, 28 Jan 2007 18:51:07 +0100
David Johnson <djohnson at jsatech.com> wrote:

> Does anyone know where I can find the latest methods on using  
> vocabularies?  I've using one approach for a while now using  
> SimpleVocabulary but that stopped working when I upgraded to 3.3.   
> The errors are "SimpleVocabulary is not called".
> 
> def getFunctions():
>      values = [ 'Black', 'Red', 'Blue' ]
>      return SimpleVocabulary.fromValues(values)
> 
> I thought this would be a good chance to build my vocabulary
> skills. I followed Stephan's book but I am receiving errors such as:
> 
>    File "/Users/djohnson/sandbox/Zope-3.3.0/build/lib.macosx-10.3- 
> fat-2.4/zope/app/form/utility.py", line 64, in _createWidget
>      field = field.bind(context)
>    File "/Users/djohnson/sandbox/Zope-3.3.0/build/lib.macosx-10.3- 
> fat-2.4/zope/schema/_field.py", line 239, in bind
>      assert ISource.providedBy(clone.vocabulary)
> 
> I figured that might be outdated, so I tried copying the "Connection  
> Names" vocabularly but again I get the same errors.
> 
> What am I missing? Where should I look?
> 

I came across this exact same error while playing with vocabularies
myself.

Here is a portion of my schema definition:

    myProperty = Choice(title=_(u"A Property"),
                        description=_(u"Testing vocabs."),
                        vocabulary="Properties",
                        required=False)

The vocabulary using the utility directive (since vocabulary
is deprecated, I believe).

   <utility
       name="Properties"
       permission="zope.Public"
       provides="zope.schema.interfaces.IVocabularyFactory"
       component=".myproperty.getProperties"
       />

With a function as the component (in myproperty.py):

# Accepting the context argument was important even though
# it is not used in this function.
def getProperties(context):
    """
    return a vocabulary of properties.
    """
    list = ["one", "two"]
    return SimpleVocabulary.fromValues(list)

One trick was to use the provides=IVocabularyFactory line in the
vocabulary's utility directive.  I had other ComponentLookup issues
before I set it to that.

I hope this helps because that assert error is in my logs
and I fixed it but I can't remember exactly what the key
change was at the time.  ;-)

Vinny




More information about the Zope3-users mailing list