diff --git a/bin/addons/base/res/res_lang.py b/bin/addons/base/res/res_lang.py index d45824cc9ec..8a3af7dd175 100644 --- a/bin/addons/base/res/res_lang.py +++ b/bin/addons/base/res/res_lang.py @@ -21,6 +21,7 @@ from osv import fields, osv from locale import localeconv +import tools class lang(osv.osv): _name = "res.lang" @@ -59,23 +60,35 @@ class lang(osv.osv): ('name_uniq', 'unique (name)', 'The name of the language must be unique !'), ('code_uniq', 'unique (code)', 'The code of the language must be unique !'), ] - def _group(self,cr,uid,ids,s, monetary=False): + + @tools.cache(skiparg=3) + def _lang_data_get(self, cr, uid, lang_id): conv = localeconv() - - lang_obj=self.browse(cr,uid,ids[0]) + lang_obj=self.browse(cr,uid,lang_id) thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep'] + decimal_point = lang_obj.decimal_point + grouping = lang_obj.grouping + return (grouping, thousands_sep, decimal_point) - grouping = eval(lang_obj.grouping) + def write(self, cr, uid, ids, vals, context=None): + for lang_id in ids : + self._lang_data_get.clear_cache(cr.dbname,lang_id= lang_id) + return super(lang, self).write(cr, uid, ids, vals, context) + def _group(self, cr, uid, ids, s, monetary=False, grouping=False, thousands_sep=''): + grouping = eval(grouping) + if not grouping: return (s, 0) result = "" seps = 0 spaces = "" + if s[-1] == ' ': sp = s.find(' ') spaces = s[sp:] s = s[:sp] + while s and grouping: # if grouping is -1, we are done if grouping[0] == -1: @@ -101,13 +114,13 @@ class lang(osv.osv): seps += 1 return result + spaces, seps - def format(self,cr,uid,ids,percent, value, grouping=False, monetary=False): + def format(self, cr, uid, ids, percent, value, grouping=False, monetary=False): """ Format() will return the language-specific output for float values""" if percent[0] != '%': raise ValueError("format() must be given exactly one %char format specifier") - lang_obj=self.browse(cr,uid,ids[0]) + lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0]) formatted = percent % value # floats and decimal ints need special action! @@ -116,9 +129,8 @@ class lang(osv.osv): parts = formatted.split('.') if grouping: - parts[0], seps = self._group(cr,uid,ids,parts[0], monetary=monetary) + parts[0], seps = self._group(cr,uid,ids,parts[0], monetary=monetary, grouping=lang_grouping, thousands_sep=thousands_sep) - decimal_point=lang_obj.decimal_point formatted = decimal_point.join(parts) while seps: sp = formatted.find(' ') @@ -127,7 +139,7 @@ class lang(osv.osv): seps -= 1 elif percent[-1] in 'diu': if grouping: - formatted = self._group(cr,uid,ids,formatted, monetary=monetary)[0] + formatted = self._group(cr,uid,ids,formatted, monetary=monetary, grouping=lang_grouping, thousands_sep=thousands_sep)[0] return formatted diff --git a/bin/tools/__init__.py b/bin/tools/__init__.py index 78c77edf394..9b7bb84a57f 100644 --- a/bin/tools/__init__.py +++ b/bin/tools/__init__.py @@ -24,7 +24,6 @@ import win32 from config import * from misc import * from convert import * -from yaml_test import * from translate import * from graph import graph from amount_to_text import * diff --git a/bin/tools/convert.py b/bin/tools/convert.py index db3edf380f7..2e16237f50a 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -37,6 +37,7 @@ import netsvc import osv import pooler from config import config +from yaml_import import convert_yaml_import class ConvertError(Exception): def __init__(self, doc, orig_excpt): diff --git a/bin/tools/yaml_test.py b/bin/tools/yaml_import.py similarity index 95% rename from bin/tools/yaml_test.py rename to bin/tools/yaml_import.py index b4d23376c7a..2c334c9cd3c 100644 --- a/bin/tools/yaml_test.py +++ b/bin/tools/yaml_import.py @@ -31,7 +31,7 @@ class YamlTag(object): return "<%s %s>" % (self.__class__.__name__, sorted(self.__dict__.items())) class Assert(YamlTag): - def __init__(self, model, id, severity=netsvc.LOG_ERROR, string="NONAME", **kwargs): + def __init__(self, model, id, severity=logging.ERROR, string="NONAME", **kwargs): self.model = model self.id = id self.severity = severity @@ -45,7 +45,7 @@ class Record(YamlTag): super(Record, self).__init__(**kwargs) class Python(YamlTag): - def __init__(self, model, severity=netsvc.LOG_ERROR, name="NONAME", **kwargs): + def __init__(self, model, severity=logging.ERROR, name="NONAME", **kwargs): self.model= model self.severity = severity self.name = name @@ -259,7 +259,7 @@ class YamlInterpreter(object): self.filename = filename self.assert_report = TestReport() self.noupdate = noupdate - self.logger = netsvc.Logger() + self.logger = logging.getLogger(logger_channel) self.pool = pooler.get_pool(cr.dbname) self.uid = 1 self.context = {} @@ -284,7 +284,7 @@ class YamlInterpreter(object): ['&', ('name', '=', module), ('state', 'in', ['installed'])]) assert module_count == 1, """The ID "%s" refers to an uninstalled module""" % (xml_id,) if len(id) > 64: # TODO where does 64 come from (DB is 128)? should be a constant or loaded form DB - self.logger.notifyChannel(logger_channel, netsvc.LOG_ERROR, 'id: %s is to long (max: 64)' % (id,)) + self.logger.log(logging.ERROR, 'id: %s is to long (max: 64)', id) def get_id(self, xml_id): if isinstance(xml_id, types.IntType): @@ -316,8 +316,8 @@ class YamlInterpreter(object): def _log_assert_failure(self, severity, msg, *args): self.assert_report.record(False, severity) - self.logger.notifyChannel(logger_channel, severity, msg % (args)) - if getattr(logging, severity.upper()) >= config['assert_exit_level']: + self.logger.log(severity, msg, *args) + if severity >= config['assert_exit_level']: raise YamlImportAbortion('Severe assertion failure (%s), aborting.' % (severity,)) return @@ -368,7 +368,7 @@ class YamlInterpreter(object): model = self.get_model(record.model) record_dict = self._create_record(model, fields) id = self.pool.get('ir.model.data')._update(self.cr, self.uid, record.model, \ - self.module, record_dict, record.id, noupdate=self.isnoupdate(node), mode=self.mode) + self.module, record_dict, record.id, noupdate=self.isnoupdate(record), mode=self.mode) self.id_map[record.id] = int(id) if config.get('import_partial', False): self.cr.commit() @@ -404,8 +404,8 @@ class YamlInterpreter(object): self.uid = self.get_id(node.__dict__['uid']) def process_python(self, node): - def log(msg): - self.logger.notifyChannel(logger_channel, netsvc.LOG_TEST, msg) + def log(msg, *args): + self.logger.log(logging.TEST, msg, *args) python, statements = node.items()[0] model = self.get_model(python.model) statements = statements.replace("\r\n", "\n") @@ -414,9 +414,7 @@ class YamlInterpreter(object): code = compile(statements, self.filename, 'exec') eval(code, code_context) except AssertionError, e: - msg = 'Assertion "%s" FAILED in Python code.' - args = (python.name,) - self._log_assert_failure(python.severity, msg, *args) + self._log_assert_failure(python.severity, 'Assertion "%s" FAILED in Python code.', python.name) return except Exception, e: raise YamlImportAbortion(e) @@ -693,9 +691,9 @@ class YamlInterpreter(object): try: self._process_node(node) except YamlImportException, e: - self.logger.notifyChannel(logger_channel, netsvc.LOG_ERROR, e) + self.logger.log(logging.ERROR, e) except YamlImportAbortion, e: - self.logger.notifyChannel(logger_channel, netsvc.LOG_ERROR, e) + self.logger.log(logging.ERROR, e) return def _process_node(self, node): @@ -737,14 +735,14 @@ class YamlInterpreter(object): def _log(self, node, is_preceded_by_comment): if is_comment(node): is_preceded_by_comment = True - self.logger.notifyChannel(logger_channel, netsvc.LOG_TEST, node) + self.logger.log(logging.TEST, node) elif not is_preceded_by_comment: if isinstance(node, types.DictionaryType): - k, v = node.items()[0] - msg = "Creating %s\n with %s" % (k, v) - self.logger.notifyChannel(logger_channel, netsvc.LOG_TEST, msg) + msg = "Creating %s\n with %s" + args = node.items()[0] + self.logger.log(logging.TEST, msg, *args) else: - self.logger.notifyChannel(logger_channel, netsvc.LOG_TEST, node) + self.logger.log(logging.TEST, node) else: is_preceded_by_comment = False return is_preceded_by_comment