Am Samstag, 15. September 2007 18:08 schrieb Jesper Petersen:
> Hello!I'm trying to implement a DropdownWidget for my country list. In my
> app i'd like to have a dropdown menu where a user can choose a country (for
> my main content object, a job). My vocabulary is created from a list of
> strings, and stored in a local utility:
> SimpleVocabulary.fromValues( [u'AD', u'AE', 'AF', ...] )
> But in my dropdown widget i want to display the country name for each
> option too.. and not just the same value on both the value attribute and
> inside the element:
> <option value="AD">Andorra</option>

Perhaps I misunderstand your question, but AFAIK vocabulary support this 
scenario. In my application, I also have a country drop-down that is in my 
case filled from a relational database. The vocabulary looks like this:

def landVocabulary(obj):
    """Get ktoids and ktonrs from session"""
    session = zalchemy.getSession()
    laender = session.query(Land)
    laender_terms = []
    for n, land in enumerate(laender):
    return vocabulary.SimpleVocabulary(laender_terms)

# Make function a vocabulary factory
alsoProvides(landVocabulary, IVocabularyFactory)

and in my configuration:


Now I can use this vocabulary from any interface.

Best regards,

GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
Zope3-users mailing list

Reply via email to