[Grok-dev] Re: Understanding unicode
Leonardo Rochael Almeida
leorochael at gmail.com
Sun Sep 23 21:57:29 EDT 2007
The problem here is that the simple solutions either don't provide a
proper token and cause the unicode error, as reported before, or don't
provide a nice "title" for each term: SimpleVocabulary.fromItems() use
the 1st entry of each tuple as token and the 2nd as value, but
displays the token as each term "title" because it can't assume the
value is something printable to the user (say, some non-string
object).
The only way here is to be explicit. Fortunately, the explicit
solution is not all that more complicated:
>>> caipirinha_ingredients = [("agua", u"água"),
... ("cachaca", u"cachaça"),
... ("acucar", u"açúcar"),
... ("limao", u"limão)]
>>> caipirinha_ingredients_vocabulary = SimpleVocabulary(
... SimpleTerm(value=value, token=token, title=value)
... for token, value in caipirinha_ingredients)
>>> field = Choice(title=u"Ingredientes de Caipirinha",
... vocabulary=caipirinha_ingredients_vocabulary)
It would be nice if there was a SimpleUnicodeVocabulary that used
utf-7, like Philipp suggested, or even urlquote of utf-8, to
automaticallly generate tokens from unicode strings.
On 9/23/07, Sebastian Ware <sebastian at urbantalk.se> wrote:
> A recipe for this would be very much appreciated, even if it is a bit
> cumbersome :) Choice fields with only ascii representations are
> rather limited with repect to usability. I have had to use ISO-codes
> instead of country names in a current project and it is not a very
> good solution.
>
> Mvh Sebastian
>
> 23 sep 2007 kl. 18.55 skrev Uli Fouquet:
>
> > Is there a simple solution to create Choice fields with simple
> > vocabularies and umlauts? Or is the basic Choice field just too
> > limited
> > in that respect? Sorry, if that became off-topic.
> >
> > Kind regards,
> >
> > --
> > Uli
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
More information about the Grok-dev
mailing list