Actually, the problem is that these are labels in a select widget, which 
are being populated via an IS_IN_DB validator. In the IS_IN_DB validator, 
the "label" argument is a string, so the value from the selected row gets 
converted to a string, regardless of whether it is an XML object via 
filter_out (see 
http://code.google.com/p/web2py/source/browse/gluon/validators.py#473). A 
simple solution is just to change the "label" argument to a callable that 
converts the label to an XML object:

IS_IN_DB(db, db.regions.id, lambda r: XML(r.region), 
orderby='sort_order',multiple
=True)

That should do what you want and is simpler than my earlier solution (also, 
in that solution, it wasn't necessary to wrap the _value attributes in XML 
because those would just be integer id's in this case anyway).

Anthony

On Monday, September 3, 2012 6:34:48 PM UTC-4, Jose C wrote:
>
> You can also try
>>
>> import cgi
>> db.table.field.filter_in = lambda text: cgi.escape(text) #1
>>
>> db.table.field.filter_out = lambda text: XML(text) #2
>>
>
> Hi Massimo, thanks for your reply.  filter_out sounds like it could be an 
> even more elegant way of achieving this.  However I tested option 2 (placed 
> code in model file,  even restarted server for good luck) but it doesn't 
> seem to have any effect (with version 2.0.6).  The output is still 
> escaped.  
>
> filter_out is definitely working, because:
> db.table.field.filter_out = lambda text: text + 'xxx'
> has the desired effect, however the XML function doesn't do anything.
>
> I'll delve into it in more detail tomorrow and look into the source as I 
> see the filter_ options are new to 2.0.
>
>
>

-- 



Reply via email to