Well, I found a solution for this strangely undocumented issue:

format=lambda r: r.nombre.decode("utf-8", 'ignore') + ' - ' + str(r.precio) 
+ '€'.decode("utf-8", 'ignore')

Then, using the lambda and decode, it works. Maybe that the 'ignore' isn't 
neccesary, but I left there just in case.

El lunes, 19 de agosto de 2013 12:26:56 UTC-5, juan escribió:
>
> Thank you Massimo,
>
> but how can it be resolved when the format attribute must represent fields 
> in the database with special chars?. I mean, the hardcoded euro char is the 
> minor problem here.
>
> Thanks
>
>
>
> El jueves, 15 de agosto de 2013 04:07:53 UTC-5, Massimo Di Pierro escribió:
>>
>> replace
>>  format="%(nombre)s - %(precio)s€"
>>
>> with
>>
>>  format= "%(nombre)s - %(precio)s\xe2\x82\xac"
>>
>> because labels mush be in ascii (or utf8) but not unicode.
>>
>> On Wednesday, 14 August 2013 15:57:24 UTC-5, juan wrote:
>>>
>>> Hello,
>>>
>>> It seems that the format option in db.define_table isn't working 
>>> properly when deployed on GAE.
>>>
>>> Please, consider these two tables:
>>>
>>> db.define_table('ingrediente',
>>>                 Field('nombre', 'string', 
>>> requires=IS_NOT_EMPTY(error_message='Se ha de indicar el nombre')),
>>>                 Field('precio', 'decimal(2,2)', 
>>> requires=IS_NOT_EMPTY(error_message='Se ha de indicar el precio'), 
>>> default=1),
>>>                 format="%(nombre)s - %(precio)s")
>>>
>>> db.define_table('bocadillo',
>>>                 Field('nombre', 'string', 
>>> requires=IS_NOT_EMPTY(error_message='Se ha de indicar el nombre')),         
>>>           
>>>                 Field('ingredientes', 'list:reference ingrediente', 
>>> comment='Seleccionar los componentes del bocadillo prediseñado usando 
>>> Control+click.'))
>>>
>>> The problem appears only in GAE and happens when some non-english 
>>> character (áéíóú) is in the field name in the first table. It fails to 
>>> render the SQLFORM of the second table. In addition, if I set the first 
>>> table's format to the preferred
>>>
>>>  format="%(nombre)s - %(precio)s€"
>>>
>>> Note the new '€', then it always fails.
>>>
>>> Here is the GAE log:
>>>
>>> Traceback (most recent call last):
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/gluon/restricted.py",
>>>  line 212, in restricted
>>>     exec ccode in environment
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/applications/lapanza/controllers/appadmin.py",
>>>  line 433, in <module>
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/gluon/globals.py",
>>>  line 194, in <lambda>
>>>     self._caller = lambda f: f()
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/applications/lapanza/controllers/appadmin.py",
>>>  line 127, in insert
>>>     form = SQLFORM(db[table], ignore_rw=ignore_rw)
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/gluon/sqlhtml.py",
>>>  line 1140, in __init__
>>>     inp = self.widgets.options.widget(field, default)
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/gluon/sqlhtml.py",
>>>  line 278, in widget
>>>     options = requires[0].options()
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/gluon/validators.py",
>>>  line 553, in options
>>>     self.build_set()
>>>   File 
>>> "/base/data/home/apps/s~lapanzaadomicilio-hrd/1.369502662945631224/gluon/validators.py",
>>>  line 548, in build_set
>>>     self.labels = [self.label % r for r in records]UnicodeDecodeError: 
>>> 'ascii' codec can't decode byte 0xe2 in position 10: ordinal not in 
>>> range(128)
>>>
>>>
>>> Is there anything I missed, or if it's a bug, is there something I can 
>>> do?
>>>
>>> This is my first question and I am totally new to web2py, so please if 
>>> this question is already aswered, I'm sorry to bother you.
>>>
>>> Thank you
>>>
>>>
>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to