From 132b6e3762d0f800d38f4b2d9a16d17c69a55640 Mon Sep 17 00:00:00 2001 From: ced <> Date: Wed, 12 Dec 2007 13:24:31 +0000 Subject: [PATCH] Add formatLang function for the report It formats the number for the defined lang using the locale settings. bzr revid: ced-d00bbd91305d237e2bbdca471faf2a64feca68ab --- bin/report/report_sxw.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index 56c84a6cab5..908e4fda583 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -36,7 +36,7 @@ import tools import pooler import netsvc import warnings - +import locale import copy parents = { @@ -102,6 +102,7 @@ class rml_parse(object): 'setTag': self.setTag, 'removeParentNode': self.removeParentNode, 'format': self.format, + 'formatLang': self.formatLang, } self.localcontext.update(context) self.name = name @@ -152,6 +153,20 @@ class rml_parse(object): def setLang(self, lang): self.localcontext['lang'] = lang + def formatLang(self, value, digit=2): + lc, encoding = locale.getdefaultlocale() + if encoding == 'utf': + encoding = 'UTF-8' + try: + locale.setlocale(locale.LC_ALL, + (self.localcontext.get('lang', 'en_US') or 'en_US') + \ + '.' + encoding) + except Exception: + netsvc.Logger().notifyChannel('report', netsvc.LOG_WARNING, + 'report %s: unable to set locale "%s"' % (self.name, + self.localcontext.get('lang', 'en_US') or 'en_US')) + return locale.format('%.' + str(digit) + 'f', value, True) + def repeatIn(self, lst, name, nodes_parent=False): self._node.data = '' node = self._find_parent(self._node, nodes_parent or parents)