If the data are from the database, in your model definitions, you can 
specify the "represent" attribute, which is a function that takes the value 
(as well as the entire row) and can output whatever you like. It is 
automatically used in the grid, SQLTABLE, and in read-only forms, and you 
can use it more generally via rows.render() 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Rendering-rows-using-represent>
.

Alternatively, you could use filter_out 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#filter_in-and-filter_out>
 
or SQLCustomType 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Custom-Field-types--experimental->
 
to have the DAL automatically transform values when selected from the 
database (in this case, though, you will lose the original values -- only 
the transformed values will be held in the Row objects).

If the data are not from the database, then no, you have to use Python code 
to specify how you want them displayed. You can, of course, write a simple 
wrapper function customized according to your preferences.

Anthony

On Tuesday, March 22, 2016 at 12:39:42 PM UTC-4, Alfonso Serra wrote:
>
> Yes, is there a way to control how to render builtin python types (int, 
> float, NoneType, ...)?
>
> Instead of:
> None: a = None renders as "None", render as " "
> Integer: b = 1234 render as "1.234"
> Float: c = 1234.265 render as "1.234,27"
> Boolean d = True render as "ok"
> And so on...
>
> We cant change builtins __repr__ methods but is there any view mechanism 
> to control that?
>
> It would save so much work if we are allowed to render python types in the 
> view as we want without having to wrap all the variables in all the views 
> into some kind of function.
>
> Thanks!
>
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to