[z3-five] Re: Extended characters in forms

yuppie y.2005- at wcm-solutions.de
Tue May 24 08:46:15 CEST 2005


Hi!


Lennart Regebro wrote:
> On 5/23/05, Martijn Faassen <faassen at infrae.com> wrote:
> 
>>>>3. Do some magic so everything in these forms is converted to unicode
>>>>with the charset encoding in the for request.
>>>
>>>I tried #3, and you get problems with things that are for example
>>>lists of strings, so that didn't work.
>>
>>Hm, how did you try #3? I think #3 is most similar to what the Zope 3
>>publisher itself does, though I still need to go study it.
> 
> I tried making the editform and addform view-classes do this
> convertion. But, you get problems with things that are not pure
> strings, like lists and stuff.

To me this still sounds like the best approach. Converting 'lists and 
stuff' should not be too hard. This method from CMFDefault.utils might 
be useful for that:

def toUnicode(value, charset=None):
     """ Convert value to unicode.
     """
     if isinstance(value, str):
         return charset and unicode(value, charset) or unicode(value)
     elif isinstance(value, list):
         return [ toUnicode(val, charset) for val in value ]
     elif isinstance(value, tuple):
         return tuple( [ toUnicode(val, charset) for val in value ] )
     elif isinstance(value, dict):
         for key, val in value.items():
             value[key] = toUnicode(val, charset)
         return value
     else:
         return value


Cheers,

	Yuppie



More information about the z3-five mailing list