smartgrid: currency format

567 views
Skip to first unread message

Omi Chiba

unread,
Sep 28, 2011, 10:48:47 AM9/28/11
to web2py-users
Can we format 500.00 to $500.00 on smartgrid ?

Massimiliano

unread,
Sep 28, 2011, 10:53:06 AM9/28/11
to 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

unread,
Sep 28, 2011, 11:37:04 AM9/28/11
to 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

unread,
Sep 28, 2011, 11:42:13 AM9/28/11
to 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

unread,
Sep 28, 2011, 11:48:19 AM9/28/11
to 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

unread,
Sep 28, 2011, 12:02:46 PM9/28/11
to 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

unread,
Sep 28, 2011, 12:08:00 PM9/28/11
to web...@googlegroups.com
Can you post the relevant code from default.py?

-Jim

Omi Chiba

unread,
Sep 28, 2011, 12:26:29 PM9/28/11
to 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

unread,
Sep 28, 2011, 1:07:55 PM9/28/11
to 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

unread,
Sep 28, 2011, 2:12:55 PM9/28/11
to web2py-users
Oh it worked !!
My smartgrid looks so smart !!!
Reply all
Reply to author
Forward
0 new messages