From a8d4460cfc740067fe062b7e5f16bedd0e7d9972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 12 Feb 2008 11:39:26 +0100 Subject: [PATCH] Update modules, update also translation except if the translation was modified by a user --- trytond/ir/module/module.py | 8 +++++++- trytond/ir/translation.py | 16 +++++++++++----- trytond/module.py | 11 +++++++---- trytond/pooler.py | 21 +++++++++++++-------- trytond/trytond.py | 11 +++++++++-- trytond/web_service/db.py | 10 +++++++++- 6 files changed, 56 insertions(+), 21 deletions(-) diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index e6805a3c73..dd29f70067 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -666,6 +666,7 @@ class ModuleInstallUpgrade(Wizard): def _upgrade_module(self, cursor, user, data, context): module_obj = self.pool.get('ir.module.module') + lang_obj = self.pool.get('ir.lang') dbname = cursor.dbname db = get_db(dbname) cursor = db.cursor() @@ -673,9 +674,14 @@ class ModuleInstallUpgrade(Wizard): ('state', 'in', ['to upgrade', 'to remove', 'to install']), ], context=context) module_obj.download(cursor, user, module_ids, context=context) + lang_ids = lang_obj.search(cursor, user, [ + ('translatable', '=', True), + ], context=context) + lang = [x.code for x in lang_obj.browse(cursor, user, lang_ids, + context=context)] cursor.commit() cursor.close() - restart_pool(dbname, update_module=True) + restart_pool(dbname, update_module=True, lang=lang) return {} states = { diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 76efa7285d..76d1879664 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -28,7 +28,6 @@ csv.register_dialect("TRYTON", TRYTON) class Translation(OSV, Cacheable): "Translation" _name = "ir.translation" - _log_access = False _description = __doc__ def _get_language(self, cursor, user, context): @@ -279,10 +278,17 @@ class Translation(OSV, Cacheable): 'fuzzy': fuzzy, }, context=ctx)) else: - self.write(cursor, user, ids, { - 'value': value, - 'fuzzy': fuzzy, - }, context=ctx) + cursor.execute('SELECT id FROM ir_translation ' \ + 'WHERE (write_uid IS NULL OR write_uid = 0) ' \ + 'AND id IN ' \ + '(' + ','.join(['%d' for x in ids]) + ')', + ids) + ids2 = [x[0] for x in cursor.fetchall()] + if ids2: + self.write(cursor, user, ids2, { + 'value': value, + 'fuzzy': fuzzy, + }, context=ctx) translation_ids += ids cursor.execute('DELETE FROM ir_translation ' \ diff --git a/trytond/module.py b/trytond/module.py index e8b7cb8e1a..9f38fbb75b 100644 --- a/trytond/module.py +++ b/trytond/module.py @@ -164,7 +164,9 @@ def init_module_wizards(cursor, module_name, wizard_list): for wizard in wizard_list: wizard.auto_init(cursor, module_name) -def load_module_graph(cursor, graph, lang): +def load_module_graph(cursor, graph, lang=None): + if lang is None: + lang = ['en_US'] package_todo = [] for package in graph: module = package.name @@ -207,12 +209,13 @@ def load_module_graph(cursor, graph, lang): tools.convert_xml_import(cursor, module, tools.file_open(OPJ(module, filename))) for filename in package.datas.get('translation', []): - if lang != os.path.splitext(filename)[0]: + lang2 = os.path.splitext(filename)[0] + if lang2 not in lang: continue Logger().notify_channel('init', LOG_INFO, 'module:%s:loading %s' % (module, filename)) translation_obj = pool.get('ir.translation') - translation_obj.translation_import(cursor, 0, lang, module, + translation_obj.translation_import(cursor, 0, lang2, module, tools.file_open(OPJ(module, filename))) if demo: cursor.execute('UPDATE ir_module_module SET demo = %s ' \ @@ -258,7 +261,7 @@ def register_classes(): Logger().notify_channel('init', LOG_ERROR, 'Couldn\'t find module %s' % module) -def load_modules(database, force_demo=False, update_module=False, lang='en_US'): +def load_modules(database, force_demo=False, update_module=False, lang=None): cursor = database.cursor() force = [] if force_demo: diff --git a/trytond/pooler.py b/trytond/pooler.py index bbc35d017b..80562f15dc 100644 --- a/trytond/pooler.py +++ b/trytond/pooler.py @@ -7,7 +7,7 @@ _POOL_WIZARD = {} _POOL_REPORT = {} def get_db_and_pool(db_name, force_demo=False, update_module=False, - wizard=False, report=False, lang='en_US'): + wizard=False, report=False, lang=None): if db_name in _DB: database = _DB[db_name] else: @@ -46,9 +46,12 @@ def get_db_and_pool(db_name, force_demo=False, update_module=False, return database, pool_report return database, pool -def restart_pool(db_name, force_demo=False, update_module=False): +def restart_pool(db_name, force_demo=False, update_module=False, lang=None): del _POOL[db_name] - return get_db_and_pool(db_name, force_demo, update_module=update_module) + del _POOL_WIZARD[db_name] + del _POOL_REPORT[db_name] + return get_db_and_pool(db_name, force_demo, update_module=update_module, + lang=lang) def close_db(db_name): if db_name in _DB: @@ -70,14 +73,16 @@ def get_db_only(db_name): def get_db(db_name): return get_db_and_pool(db_name)[0] -def get_pool(db_name, force_demo=False, update_module=False, lang='en_US'): +def get_pool(db_name, force_demo=False, update_module=False, lang=None): pool = get_db_and_pool(db_name, force_demo, update_module, lang=lang)[1] return pool -def get_pool_wizard(db_name, force_demo=False, update_module=False): - pool = get_db_and_pool(db_name, force_demo, update_module, wizard=True)[1] +def get_pool_wizard(db_name, force_demo=False, update_module=False, lang=None): + pool = get_db_and_pool(db_name, force_demo, update_module, wizard=True, + lang=lang)[1] return pool -def get_pool_report(db_name, force_demo=False, update_module=False): - pool = get_db_and_pool(db_name, force_demo, update_module, report=True)[1] +def get_pool_report(db_name, force_demo=False, update_module=False, lang=None): + pool = get_db_and_pool(db_name, force_demo, update_module, report=True, + lang=lang)[1] return pool diff --git a/trytond/trytond.py b/trytond/trytond.py index 28e28eb5a2..742b8eb68a 100644 --- a/trytond/trytond.py +++ b/trytond/trytond.py @@ -113,13 +113,20 @@ class TrytonServer(object): if not CONFIG['without_demo']: CONFIG["demo"]['all'] = 1 cursor.commit() - cursor.close() register_classes() if db_name: + lang = None + if cursor: + cursor.execute('SELECT code FROM ir_lang ' \ + 'WHERE translatable = True') + lang = [x[0] for x in cursor.fetchall()] pooler.get_db_and_pool(db_name, - update_module=bool(CONFIG['init'] or CONFIG['update'])) + update_module=bool(CONFIG['init'] or CONFIG['update']), + lang=lang) + if cursor: + cursor.close() if CONFIG["stop_after_init"]: sys.exit(0) diff --git a/trytond/web_service/db.py b/trytond/web_service/db.py index 6693265981..764f1fbce9 100644 --- a/trytond/web_service/db.py +++ b/trytond/web_service/db.py @@ -41,8 +41,16 @@ class DB(Service): cursor.commit() cursor.close() cursor = None - pooler.get_pool(db_name, demo, update_module=True, lang=lang) + pooler.get_pool(db_name, demo, update_module=True, lang=[lang]) cursor = sql_db.db_connect(db_name).cursor() + if lang != 'en_US': + cursor.execute('UPDATE ir_lang ' \ + 'SET translatable = True ' \ + 'WHERE code = %s', (lang,)) + cursor.execute('UPDATE res_user ' \ + 'SET language = %s ' \ + 'WHERE login <> \'root\'', (lang,)) + cursor.commit() cursor.execute('SELECT login, password, name ' \ 'FROM res_user ' \ 'WHERE login <> \'root\' ORDER BY login')