smartgrid: currency format

Visto 567 veces
Saltar al primer mensaje no leído

Omi Chiba

no leída,
28 sept 2011, 10:48:4728/9/11
a web2py-users
Can we format 500.00 to $500.00 on smartgrid ?

Massimiliano

no leída,
28 sept 2011, 10:53:0628/9/11
a web...@googlegroups.com
Is there a reason that you want to format on the grid?

 because you can do it in field.represent:

db.yourtable.yourfield = lambda value, row: '$ %.2f' % (0.0 if value == None else value)


On Wed, Sep 28, 2011 at 4:48 PM, Omi Chiba <ochi...@gmail.com> wrote:
Can we format 500.00 to $500.00 on smartgrid ?



--
Massimiliano

Omi Chiba

no leída,
28 sept 2011, 11:37:0428/9/11
a web2py-users
Wow ! This is what I want.
Thanks !!

On Sep 28, 9:53 am, Massimiliano <mbelle...@gmail.com> wrote:
> Is there a reason that you want to format on the grid?
>
>  because you can do it in field.represent:
>
> db.yourtable.yourfield = lambda value, row: '$ %.2f' % (0.0 if value == None
> else value)
>

Omi Chiba

no leída,
28 sept 2011, 11:42:1328/9/11
a web2py-users
Um, actually one more question.
Now I have two represent and riht now either one of them work but not
both. How I can combine them together ??

# Currency format
db.Product.List_Price.represent = lambda value, row: '$ %.2f' % (0.0
if value == None else value)

# text-align: right
db.Product.List_Price.represent = lambda value, row:
XML(DIV(value,_style='text-align: right;'))

Jim Steil

no leída,
28 sept 2011, 11:48:1928/9/11
a web...@googlegroups.com
untested

db.Product.List_Price.represent = lambda value, row: XML(DIV('$ %.2f' % (0.0 if value == None else value),_style='text-align: right;'))

Omi Chiba

no leída,
28 sept 2011, 12:02:4628/9/11
a web2py-users
Jim,

close but I got a following error.

Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 194, in
restricted
exec ccode in environment
File "/home/www-data/web2py/applications/pricelist/controllers/
default.py", line 95, in <module>
@auth.requires_signature()
File "/home/www-data/web2py/gluon/tools.py", line 2494, in
requires_signature
return
self.requires(URL.verify(current.request,user_signature=True))
File "/home/www-data/web2py/gluon/html.py", line 352, in verifyURL
hmac_key = current.session.auth.hmac_key
AttributeError: 'NoneType' object has no attribute 'hmac_key'

Jim Steil

no leída,
28 sept 2011, 12:08:0028/9/11
a web...@googlegroups.com
Can you post the relevant code from default.py?

-Jim

Omi Chiba

no leída,
28 sept 2011, 12:26:2928/9/11
a web2py-users
It's smartgrid so nothing really in default.py.

just this one.

def admin():
products = SQLFORM.grid(db.Product,deletable=False, paginate=10)
return dict(products = products)

This is my table.
db.define_table('Product',
Field('Part_Number'),
Field('List_Price', 'decimal(13,2)'))

Massimiliano

no leída,
28 sept 2011, 13:07:5528/9/11
a web...@googlegroups.com
This one should work...

db.Product.List_Price.represent = lambda value, row: DIV('€ %.2f' % (0.0 if value == None else value), _style='text-align: right;')
--
Massimiliano

Omi Chiba

no leída,
28 sept 2011, 14:12:5528/9/11
a web2py-users
Oh it worked !!
My smartgrid looks so smart !!!
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos