Money-formatted numbers in SQLFORM grid

Money-formatted numbers in SQLFORM grid

In web2py SQLFORM grid, numbers are shown unformatted and left-aligned. It will be better if the numbers or money values are currency formatted, to make it easier to read. And better yet if those numbers right-aligned in the grid / table. We can use represent in models to do the job, like:

(more…)

Convert number to money format in web2py

At some point in doing web application using web2py/Python I need to show numbers in money formatted string. Seems a little problem easy to handle, at first. After searching about money at Python Package Index then I know it was quite complex matter involved many things…
Anyway, the money format for my purpose it is enough to use simple function to convert number to money formatted string, and I use “moneyfmt” recipe I found at Python Docs, modified it a little, set places=0  as default, add condition if places == 0  to automatically set dp=''  if places=0, so I don’t have to set “dp” parameter when I need to change the number of “places”.

(more…)

Populate a field based on other field in web2py

We can fill a field based on another field, for example to calculate/compute a total value.

(more…)