Unicode support for class StringWidget(FormWidget) at web2py.gluon.sqlhtml

16 views
Skip to first unread message

AndCycle

unread,
Oct 2, 2009, 6:44:43 AM10/2/09
to web2py-users
I simply hit the unicode issue here,

I know I can do this by manual access lol

what I did

Field('rating', type='string', default=u'普遍')

at db definition

then tried to create crud form (yup, I am a lazy guy)

def post():
return dict(form=crud.create(db.uploads))

boom,

it hit a str func at line 91

79 -class StringWidget(FormWidget):
80
81 @staticmethod
82 - def widget(field, value, **attributes):
83 """
84 generates an INPUT text tag.
85
86 see also: :meth:`FormWidget.widget`
87 """
88
89 default = dict(
90 _type = 'text',
91 value = (value!=None and str(value)) or '',
92 )
93 attr = StringWidget._attributes(field, default, **attributes) 94 95
return INPUT(**attr)

here is the traceback

Traceback (most recent call last):
File "gluon/restricted.py", line 178, in restricted
File "C:/Users/AndCycle/Documents/work/corelight/case/web2py/
applications/eland/controllers/upload.py", line 15, in <module>
File "gluon/globals.py", line 102, in <lambda>
File "C:/Users/AndCycle/Documents/work/corelight/case/web2py/
applications/eland/controllers/upload.py", line 9, in post
File "gluon/tools.py", line 1892, in create
File "gluon/tools.py", line 1830, in update
File "gluon/sqlhtml.py", line 624, in __init__
File "gluon/sqlhtml.py", line 91, in widget
UnicodeEncodeError: 'ascii' codec can't encode characters in position
0-1: ordinal not in range(128)


mdipierro

unread,
Oct 2, 2009, 9:28:49 AM10/2/09
to web2py-users
Can you try

Field('rating', type='string', default=u'普遍'.encode('utf8'))

Iceberg

unread,
Oct 2, 2009, 10:48:02 PM10/2/09
to web2py-users
@AndCycle:

I believe Massimo's suggestion should solve the problem.

One more tips. If you put this line at the beginning of your source
code,
# coding: utf8
and making sure your source code file itself is in utf8, then you can
simply try:
Field('rating', type='string', default='普遍')
Much straightforward. Isn't it?

PS: I use Chinese too. ;-)
Reply all
Reply to author
Forward
0 new messages