I am not sure I am convinced this
return (refs and ', '.join(f(r,x.id) for x in refs) or '')
always works but for now it is in trunk.
On Wednesday, 21 August 2013 19:26:45 UTC-5, juan wrote:
>
> The issue wasnt completely resolved that way, there were problems with
> list:reference in updates and some weird behaviour, always involving lists
> but no simple references, so I debugged my way down to the web2py code and
> finally found the problem.
>
> In the line 6860 of the file gluon/dal.py, this is written:
>
> return (refs and ', '.join(str(f(r,x.id)) for x in refs) or '')
>
> Instead, this code below should be written (as is in the case of a non
> list reference except for the loop):
>
> return (refs and ', '.join(f(r,x.id) for x in refs) or '')
> [eliminate de str()]
>
> This plus the little code stated before solves the encoding problems in
> GAE, now all the format attributes work as expected.
>
> My version of web2py is 2.5.1-stable+timestamp.2013.06.06.15.39.19
>
> I think this change would be OK, I dont know what the developers would
> think about this.
>
> Thanks Massimo for this great tool.
>
> El martes, 20 de agosto de 2013 10:31:13 UTC-5, juan escribió:
>>
>> 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.