copying simple text field to richtext field

24 views
Skip to first unread message

Francisco Maria Moyano Casco

unread,
Jan 25, 2018, 8:40:23 AM1/25/18
to tryton
Hi,
I'm having problems trying to copying text from a text field to a richtext field.

I had success with normal characters, but when I try with special characters and some others (ñ,Ñ,áéíóú), it starts to behave unnormal.

Some example of the code I'm using is:

@classmethod
def prepare_richtext(cls,message=''):
from BeautifulSoup import BeautifulStoneSoup
import cgi
res = ''
message = message.decode('utf-8')
message = unicode(message)
message = cgi.escape(message).encode('ascii', 'xmlcharrefreplace')
res += "<div><b>"\
+(datetime.now()+timedelta(hours=-3)).strftime("%d-%m-%Y %H:%M:%S")\
+" - "
res += message+" </b></div>"
res = unicode(BeautifulStoneSoup(res,
convertEntities=BeautifulStoneSoup.ALL_ENTITIES))
return res

For example: i wrote one single "ñ" on the text field and goes unnormal (doesn't copy the character, just add some other; and tryton ask me once and again to save the form when I want to reload/close it). But, when I wrote two ("ññ"), it goes well.

Regards.
Francisco

Cédric Krier

unread,
Jan 25, 2018, 9:30:09 AM1/25/18
to tryton
Probably https://bugs.tryton.org/issue5182

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Francisco Maria Moyano Casco

unread,
Jan 25, 2018, 12:51:39 PM1/25/18
to tryton
It looks like it is. It's there anyway to force/set the encoding to chardet?

There is a hook to solve it. Simple using the comment tag <!-- -->, and write inside 2 or 3 ñ, but the richtext doesn't recognize the <!-- -_> comment tags.

Thanks
Francisco

Cédric Krier

unread,
Jan 25, 2018, 8:25:07 PM1/25/18
to tryton
I guess you could escape all non-ascii chars.

Francisco Maria Moyano Casco

unread,
Jan 30, 2018, 8:08:35 AM1/30/18
to tryton
Thanks for the answer, but got nothing.
I guess is the chardet and the auto/heuristic determination of the encoding.On a python console, importing got the same behaviour.
Once again, thanks
Francisco
Reply all
Reply to author
Forward
0 new messages