I'm stuck with encodings in tg forms:
I have this form definition where the "renda" field is likely to to
receive non ascii characters:
class formRendas(widgets.WidgetsList):
cliente =
widgets.TextField(validator=validators.OneOf(Clientes.keys() ) )
renda = widgets.TextArea( validator=validators.NotEmpty, rows=3,
cols=40)
valor = widgets.TextField(validator=validators.Int)
cod_ctb =
widgets.TextField(validator=validators.OneOf(CTB.keys() ) )
agrega = widgets.SingleSelectField(options=[('Sim', "Sim"),
('Nao', "Nao")], default='Nao')
the table is defined by this class in model.py:
class Rendas(SQLObject):
cliente = StringCol(length=6)
renda = UnicodeCol(dbEncoding='latin-1', length=80,
alternateID=True)
valor = DecimalCol(size=10, precision=2)
cod_ctb = StringCol(length=3)
agrega = EnumCol(enumValues=['Sim', 'Nao'])
activa = EnumCol(enumValues=['Sim', 'Nao'])
and the methot where the error is raised is:
def guardar(self, cliente, renda, valor, cod_ctb, agrega,
act='Sim'):
b=Rendas(cliente=cliente, renda=renda, valor=valor,
cod_ctb=cod_ctb, agrega=agrega, activa=act)
raise redirect("/index")
When I submit the form I get:
Page handler: <bound method Root.guardar of <rendas.controllers.Root
object at 0x0160DB70>>
Traceback (most recent call last):
File "c:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy
\_cphttptools.py", line 105, in _run
self.main()
File "c:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy
\_cphttptools.py", line 254, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in guardar
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 336, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\database.py", line 303, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 351, in <lambda>
mapping, fragment, args, kw)))
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 378, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\errorhandling.py", line 73, in try_call
return func(self, *args, **kw)
File "<string>", line 3, in guardar
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 173, in validate
return errorhandling.run_with_errors(errors, func, *args, **kw)
File "c:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\errorhandling.py", line 113, in run_with_errors
return func(self, *args, **kw)
File "D:\rendas\rendas\controllers.py", line 66, in guardar
b=Rendas(cliente=cliente, renda=renda, valor=valor,
cod_ctb=cod_ctb, agrega=agrega, activa=act)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\declarative.py", line 94, in _wrapper
return fn(self, *args, **kwargs)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\main.py", line 1214, in __init__
self._create(id, **kw)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\main.py", line 1245, in _create
self._SO_finishCreate(id)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\main.py", line 1269, in _SO_finishCreate
id, names, values)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\dbconnection.py", line 849, in queryInsertID
self._connection, soInstance, id, names, values)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\sqlite\sqliteconnection.py", line 214, in _queryInsertID
q = self._insertSQL(table, names, values)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\sqlite\sqliteconnection.py", line 232, in _insertSQL
return DBAPI._insertSQL(self, table, names, values)
File "c:\python25\lib\site-packages\SQLObject-0.9.0-py2.5.egg
\sqlobject\dbconnection.py", line 390, in _insertSQL
', '.join([self.sqlrepr(v) for v in values])))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position
1: ordinal not in range(128)
It's a biginners question, I don't know much about encodings, but I
can handle it in reportlab ...
Thank's for any help
Paulino
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---