Update modules, update also translation except if the translation was modified

by a user
This commit is contained in:
Cédric Krier committed 2008-02-12 11:39:26 +01:00
1 parent 8abdab8ecb
commit a8d4460cfc
6 files changed
+56 -21

No files matched your search

+7 -1
View File
@@ -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 = {
+11 -5
View File
@@ -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 ' \
+7 -4
View File
@@ -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:
+13 -8
View File
@@ -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
+9 -2
View File
@@ -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)
+9 -1
View File
@@ -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')