I solved using temporarily this:
def Moeda(valor, formatado=True):
from locale import setlocale, currency, LC_ALL
try:
setlocale(LC_ALL,'pt_BR.UTF-8')
except:
setlocale(LC_ALL,'portuguese')
if formatado:
return 'R$ %s' % currency(valor, grouping=True, symbol=False)
else:
return currency(valor, grouping=False, symbol=False).replace(',','')
>>> Moeda(10000)
R$ 10.000,00
This will be okay until I have more apps running on the same server, now I
have just one.
I am trying to figure out the best way
2010/8/25 Bruno Rocha <[email protected]>
> Massimo,
>
> What is your recomendation to deal with currency in web2py?
>
> 2010/8/25 Bruno Rocha <[email protected]>
>
> Look at
>> http://code.google.com/p/python-money/source/browse/trunk/money/Money.py
>>
>> Python-money does not use "locale"
>>
>> 2010/8/25 mdipierro <[email protected]>
>>
>> web2py cannot support locale because it is not thread safe, If one app
>>> changes the locale it would change it for all apps.
>>>
>>> On Aug 25, 12:07 am, Bruno Rocha <[email protected]> wrote:
>>> > Hi,
>>> >
>>> > Actually, I am using these methods to work with money formating.
>>> >
>>> > some tries with python-money and works very wellhttp://
>>> code.google.com/p/python-money/
>>> >
>>> > and sometimes
>>> >
>>> > import locale
>>> > locale.setlocale(locale.LC_ALL,('pt_BR','UTF8'))>>>
>>> locale.currency(1090909, grouping=True)
>>> >
>>> > 'R$ 1.090.909,00'
>>> >
>>> > So I a thinking about, how to include that as a DAL type? exactly in
>>> > the same way web2py threats with Upload fields, we could have a
>>> > datatype 'money' working with 'locale'
>>> >
>>> >
>>> db.define_table('product',Field('price','money',locale=('pt_BR','UTF8')))
>>> > or even declaring locale.setlocale() in the begining of the model file
>>> >
>>> > By now I am doing that with 'represent' or directly in views, but,
>>> > Is there any chance to include that in web2py core?
>>>
>>
>>
>>
>> --
>>
>> http://rochacbruno.com.br
>>
>
>
>
> --
>
> http://rochacbruno.com.br
>
--
http://rochacbruno.com.br