[Zope3-Users] "Smarter" values for values = [] in Choice schema fields?
Hermann Himmelbauer
dusty at qwer.tk
Thu Nov 6 08:13:56 EST 2008
Hi,
I quite often have Choice schema fields in my applications. In many cases,
these choice fields should have fixed values, thus I do it like this:
color = Choice( title=u"Color", values=['red', 'green', 'yellow'])
My application then uses the these values for further processing, e.g.:
if color == 'red': stop_traffic()
The problem is, that often it is more appropriate to have one value for
display, and another for internal processing (e.g. when msgid strings are
involved, when the program needs specific values etc.)
The only way I found is to set up a vocabulary and use
SimpleVocabulary.createTerm(key, n, name), however, that's quite tedious, as
I need to write quite some code, register the vocabulary etc.
So, perhaps there's a simpler solution? I'd favour something like this:
color = Choice(titel=u"Color", values = [('red', 0, u"Red"), ('green', 1,
u"Green")....])
Is that possible?
Best Regards,
Hermann
--
hermann at qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
More information about the Zope3-users
mailing list