[CPS-devel] Re: UnicodeDecodeError indexing translated titleof document.

Yves Bastide ybastide at wanadoo.fr
Fri Jun 2 18:14:52 CEST 2006


JoseLuis de la Rosa Triviño wrote:
> Hi again,
> 
> I have two use cases where I got errors:
> 
> The first one:
> 
> {{{
> title = mcat('title_ipractice_' + btool.ptool.CONTENTS_ID)
> title = title.encode('iso8859-15')
> docDef = {TITLE:title, DESCRIPT:'', HIDDE:0}
> }}}
> 
> with the encoding proposed by Yves works fine.

Fine.

> 
> The second use case, where I didn't have such luck is:
> 
> {{{
> 4  title = object.title_or_id()
> 5  title = title.encode('iso8859-15')
> 6  username = member.getProperty('fullname')
> 7  username = username.encode('iso8859-15')
> 8  logTitle = username + mcat(action + '_by') + title
> 9  logTitle = logTitle.encode('iso8859-15')
> }}}

Here you encode() too much. The encode() method exists in both the str 
and unicode types; the only one you need is unicode.encode(). Both 
title_or_id() and getProperty() return str, so don't encode 'em.

So you should try something like this:

title = object.title_or_id()
username = member.getProperty('fullname')
actionname = mcat(action + '_by').encode('iso8859-15')
logTitle = username + actionname + title

[...]
> 
> I used iso8859-15 because is the encoding that I use in my web browser but I'm not sure if this is what I should use in the code or if I should ask what encoding is currently being used in the title. How may I do that?

Your portal also has a 'Default portal charset' property (in the 
Properties tab of your site root)

yves



More information about the cps-devel mailing list

This list archive provided by Nuxeo, the leaders of open source ECM. Check out the Nuxeo 5 open source, standards-based ECM project.