Relatorio: How to locale-format a Python Decimal and preserve its precision?

When using relatorio outside of tryton, I want to locale-format Python Decimals. How can this be done?


  1. This stackoverflow answer shows a nice solution: {0:n}'.format(d) (after setting the locale, of course)
  2. I tried to find how to use this in relatorio or genshi, but the genshi documentation does not actually explain how “variables” are resolved by the template engine. (At least I was not able to spot it).

Tryton reports have some helper functions which you can use to format deciaml or floats using the locale of a language.

If you do not set any language it will use the language of the current user.

The question was about Relatorio without Tryton.

You need to use the available tools of Python like locale.format ( :warning: setting locale is not threadsafe). Or you need to use third-party library like Babel.

With the keyword argument passed to the report instance as context.

Do I understand correctly: The values have to be formatted by the model, relatorio can’t do this.