[Grok-dev] zope.schema.Choice & unicode problem

Cheefrocker1 eugen.buchmueller at googlemail.com
Wed Aug 25 09:03:53 EDT 2010



Marcel Klapschus wrote:
> 
> I have a problem with my zope.schema.Choice in combination with
> unicode-values in one of my grok projects:
> 
> q_type = zope.schema.Choice(title=u'Art', values=[u'Fehler', u'Änderung'])
> 
> Basically, that works fine but since there is an 'Ä'-Umlaut inside the
> valuelist,
> Zope keeps me crashing while zope-server starts up:
> 
> 
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in
> position 0: ordinal not in range(128)
> 
> # coding=utf-8 is set in the scriptfile of course. Umlauts work perfect in
> "title" but not for "values".
> 
> Any Idea what is causing the problem and how to solve it?
> 
> 

Hi,
try this:

from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm


def vocabulary(*terms):
    """
    Gibt ein Vokabulary zurück
    """
    return SimpleVocabulary([SimpleTerm(value, token, title) for value,
token, title in terms])


class MyInterface(zope.Interface):

  
    q_type = Choice(
        title = u"foobar",
        description = "",
        vocabulary = vocabulary(
      ('1', 'Fehler', u'Fehler'),
            ('2', 'Aenderung', u'Änderung'),),
     
        required = False,
    )

Cheefrocker
-- 
View this message in context: http://old.nabble.com/zope.schema.Choice---unicode-problem-tp29531348p29532025.html
Sent from the Grok mailing list archive at Nabble.com.



More information about the Grok-dev mailing list