[triangle-zpug] Getting DisplayList to show Values instead of keys

Rob Lineberger rob_lineberger at med.unc.edu
Thu Mar 23 17:47:09 CET 2006


Brief question, followed by a winding (but fruitless) road of 
self-discovery...

If you specify a DisplayList as the Vocabulary for an AT Field called 
building:

BUILDING = DisplayList((
    ('bank-of-america',   'Bank of America'),
    ('lineberger',        'Lineberger'),
    ('mary-ellen-jones',  'Mary Ellen Jones'),
    ('macnider',          'Macnider'),
    ('mbrb',              'Medical Biomolecular Research Building'),
    ('other',             'Other'),
    ))

...And you use the default accessor getBuilding in your page template, 
it will display the id ('mbrb' instead of 'Medical Biomolecular Research 
Building').  How do you get the getBuilding accessor to show the "value" 
instead of the "key"?

~~~~~~~~~~
I'm thinking the right way to go is to overwrite the getBuilding 
accessor, but this seems like something that should be built in 
already.  So I went to portal_skins/archetypes/base_view to see how it 
worked.  Then went to portal_skins/archetypes/widgets/selection to see 
specifically how the selection widget worked. the key lines seem to be:

tal:define="vocab python:field.Vocabulary(here) 
and 
tal:content="python:here.translate(vocab.getMsgId(item), default=vocab.getValue(item))"


Of course, this isn't actually returning the dictionary value, just the 
id.  Is there something besides getMsgId I should use?  The reference 
for Field didn't really clue me in. Thanks for any advice on the answer, 
or a better way to find the answer.


      *Vocabulary*(self, content_instance=None)

Returns a *DisplayList*.

Uses self.*vocabulary* as source.

1) Static *vocabulary

*   - is already a *DisplayList
*   - is a list of 2-tuples with strings (see above)
   - is a list of strings (in this case a *DisplayList
*     with key=value will be created)

2) Dynamic *vocabulary*:

   - precondition: a content_instance is given.

   - has to return a:

        * *DisplayList* or
        * list of strings or
        * list of 2-tuples with strings:
            '[("key1","value 1"),("key 2","value 2"),]'

   - the output is postprocessed like a static *vocabulary*.

   - *vocabulary* is a string:
        if a method with the name of the string exists it will be called

   - *vocabulary* is a class implementing IVocabulary:
        the "getDisplayList" method of the class will be called.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/triangle-zpug/attachments/20060323/d187bb72/attachment.htm


More information about the triangle-zpug mailing list