merting from the trunk and improvement in the form rng

bzr revid: mga@tinyerp.com-20081216193357-vblydydhp7f9ljdo
This commit is contained in:
Mantavya Gajjar
2008-12-17 01:03:57 +05:30
11 changed files with 79 additions and 46 deletions
+4 -4
View File
@@ -545,11 +545,11 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
status={}
cr = db.cursor()
force = []
if force_demo:
force.append('demo')
pool = pooler.get_pool(cr.dbname)
try:
force = []
if force_demo:
force.append('demo')
pool = pooler.get_pool(cr.dbname)
report = tools.assertion_report()
if update_module:
basegraph = create_graph(['base'], force)
+1 -1
View File
@@ -28,7 +28,7 @@ import os
def _check_xml(self, cr, uid, ids, context={}):
for view in self.browse(cr, uid, ids, context):
eview = etree.fromstring(view.arch)
eview = etree.fromstring(view.arch.encode('utf8'))
frng = tools.file_open(os.path.join('base','rng','view.rng'))
relaxng = etree.RelaxNG(file=frng)
if not relaxng.validate(eview):
+2 -1
View File
@@ -206,7 +206,8 @@ class ir_values(osv.osv):
del fields[pos]
else:
pos+=1
datas = self.pool.get(model).read(cr, uid, [id], fields, context)[0]
datas = self.pool.get(model).read(cr, uid, [id], fields, context)
datas= datas and datas[0] or None
if not datas:
#ir_del(cr, uid, x[0])
return False
@@ -26,7 +26,6 @@ import base64
import StringIO
import csv
import pooler
from osv import fields,osv
@@ -51,7 +50,6 @@ class wizard_export_lang(osv.osv_memory):
mods = map(lambda m: m.name, this.modules) or ['all']
mods.sort()
buf=StringIO.StringIO()
tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname)
if this.format == 'csv':
this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.")
@@ -64,7 +62,6 @@ class wizard_export_lang(osv.osv_memory):
this.advice = _('Save this document to a .tgz file. This archive containt UTF-8 %s files and may be uploaded to launchpad.') % (ext,)
this.name = "%s.%s" % (this.lang or _('new'), this.format)
out=base64.encodestring(buf.getvalue())
buf.close()
return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice, 'name':this.name}, context=context)
@@ -54,11 +54,8 @@ class wizard_lang_install(wizard.interface):
modobj.update_translations(cr, uid, mids, lang)
return {}
def _get_language(sel, cr, uid, context):
return tools.scan_languages()
fields_form = {
'lang': {'string':'Language', 'type':'selection', 'selection':_get_language,
'lang': {'string':'Language', 'type':'selection', 'selection':tools.scan_languages(),
},
}
+5 -1
View File
@@ -699,7 +699,11 @@ class related(function):
for i in range(len(self.arg)):
field_detail = self._relations[i]
relation = field_detail['object']
if not t_data[self.arg[i]]:
try:
if not t_data[self.arg[i]]:
t_data = False
break
except:
t_data = False
break
if field_detail['type'] in ('one2many', 'many2many'):
+11 -3
View File
@@ -918,6 +918,12 @@ class orm_template(object):
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
if not context:
context = {}
def encode(s):
if isinstance(s, unicode):
return s.encode('utf8')
return s
def _inherit_apply(src, inherit):
def _find(node, node2):
if node2.nodeType == node2.ELEMENT_NODE and node2.localName == 'xpath':
@@ -940,9 +946,11 @@ class orm_template(object):
if res:
return res
return None
doc_src = dom.minidom.parseString(src)
doc_dest = dom.minidom.parseString(inherit)
netsvc.Logger().notifyChannel('orm', netsvc.LOG_DEBUG, type(src))
doc_src = dom.minidom.parseString(encode(src))
doc_dest = dom.minidom.parseString(encode(inherit))
toparse = doc_dest.childNodes
while len(toparse):
node2 = toparse.pop(0)
@@ -1057,7 +1065,7 @@ class orm_template(object):
result['field_parent'] = False
result['view_id'] = 0
doc = dom.minidom.parseString(result['arch'].encode('utf-8'))
doc = dom.minidom.parseString(encode(result['arch']))
xarch, xfields = self.__view_look_dom_arch(cr, user, doc, context=context)
result['arch'] = xarch
result['fields'] = xfields
+1 -1
View File
@@ -215,7 +215,7 @@ class PoolManager(object):
logger.notifyChannel('dbpool', netsvc.LOG_INFO, 'Connecting to %s' % (db_name,))
PoolManager._pools[db_name] = ConnectionPool(ThreadedConnectionPool(1, PoolManager.maxconn, PoolManager.dsn(db_name)), db_name)
except Exception, e:
logger.notifyChannel('dbpool', netsvc.LOG_CRITICAL, 'Unable to connect to %s: %s' % (db_name, e.message))
logger.notifyChannel('dbpool', netsvc.LOG_ERROR, 'Unable to connect to %s: %s' % (db_name, e.message))
raise
return PoolManager._pools[db_name]
get = staticmethod(get)
+6 -2
View File
@@ -20,8 +20,12 @@
#
##############################################################################
import ConfigParser,optparse,os,sys
import netsvc,logging
import ConfigParser
import optparse
import os
import sys
import netsvc
import logging
import release
class configmanager(object):
+39 -24
View File
@@ -338,10 +338,17 @@ def trans_generate(lang, modules, dbname=None):
tuple = (module, type, name, id, source)
if source and tuple not in _to_translate:
_to_translate.append(tuple)
def encode(s):
if isinstance(s, unicode):
return s.encode('utf8')
return s
for (xml_name,model,res_id,module) in cr.fetchall():
xml_name = module+'.'+xml_name
module = encode(module)
model = encode(model)
xml_name = "%s.%s" % (module, encode(xml_name))
if not pool.get(model):
logger.notifyChannel("db", netsvc.LOG_ERROR, "unable to find object %r" % (model,))
continue
@@ -349,27 +356,32 @@ def trans_generate(lang, modules, dbname=None):
if model=='ir.ui.view':
d = xml.dom.minidom.parseString(obj.arch)
for t in trans_parse_view(d.documentElement):
push_translation(module, 'view', obj.model, 0, t)
push_translation(module, 'view', encode(obj.model), 0, t)
elif model=='ir.actions.wizard':
service_name = 'wizard.'+obj.wiz_name
service_name = 'wizard.'+encode(obj.wiz_name)
obj2 = netsvc._service[service_name]
for state_name, state_def in obj2.states.iteritems():
if 'result' in state_def:
result = state_def['result']
if result['type'] != 'form':
continue
name = obj.wiz_name + ',' + state_name
name = "%s,%s" % (encode(obj.wiz_name), state_name)
def_params = {
'string': ('wizard_field', lambda s: [encode(s)]),
'selection': ('selection', lambda s: [encode(e[1]) for e in s]),
'help': ('help', lambda s: [encode(s)]),
}
# export fields
for field_name, field_def in result['fields'].iteritems():
res_name = name + ',' + field_name
if 'string' in field_def:
source = field_def['string']
push_translation(module, 'wizard_field', res_name, 0, source.encode('utf8'))
if 'selection' in field_def:
for key, val in field_def['selection']:
push_translation(module, 'selection', res_name, 0, val.encode('utf8'))
for fn in def_params:
if fn in field_def:
transtype, modifier = def_params[fn]
for val in modifier(field_def[fn]):
push_translation(module, transtype, res_name, 0, val)
# export arch
arch = result['arch']
@@ -386,17 +398,17 @@ def trans_generate(lang, modules, dbname=None):
push_translation(module, 'wizard_button', res_name, 0, button_label)
elif model=='ir.model.fields':
field_name = obj.name
field_name = encode(obj.name)
objmodel = pool.get(obj.model)
if not objmodel or not field_name in objmodel._columns:
continue
field_def = objmodel._columns[field_name]
name = obj.model + "," + field_name
push_translation(module, 'field', name, 0, field_def.string.encode('utf8'))
name = "%s,%s" % (encode(obj.model), field_name)
push_translation(module, 'field', name, 0, encode(field_def.string))
if field_def.help:
push_translation(module, 'help', name, 0, field_def.help.encode('utf8'))
push_translation(module, 'help', name, 0, encode(field_def.help))
if field_def.translate:
ids = objmodel.search(cr, uid, [])
@@ -410,14 +422,14 @@ def trans_generate(lang, modules, dbname=None):
('res_id', '=', res_id),
])
if not model_data_ids:
push_translation(module, 'model', name, 0, obj_value[field_name])
push_translation(module, 'model', name, 0, encode(obj_value[field_name]))
if hasattr(field_def, 'selection') and isinstance(field_def.selection, (list, tuple)):
for key, val in field_def.selection:
push_translation(module, 'selection', name, 0, val.encode('utf8'))
push_translation(module, 'selection', name, 0, encode(val))
elif model=='ir.actions.report.xml':
name = obj.report_name
name = encode(obj.report_name)
fname = ""
if obj.report_rml:
fname = obj.report_rml
@@ -438,13 +450,13 @@ def trans_generate(lang, modules, dbname=None):
for constraint in pool.get(model)._constraints:
msg = constraint[1]
push_translation(module, 'constraint', model, 0, msg.encode('utf8'))
push_translation(module, 'constraint', model, 0, encode(msg))
for field_name,field_def in pool.get(model)._columns.items():
if field_def.translate:
name = model + "," + field_name
trad = getattr(obj, field_name) or ''
push_translation(module, 'model', name, xml_name, trad)
push_translation(module, 'model', name, xml_name, encode(trad))
# parse source code for _() calls
def get_module_from_path(path):
@@ -470,14 +482,17 @@ def trans_generate(lang, modules, dbname=None):
'[^a-zA-Z0-9_]_\([\s]*["\'](.+?)["\'][\s]*\)',
code_string, re.M)
for i in iter:
push_translation(module, 'code', frelativepath, 0, i.group(1).encode('utf8'))
push_translation(module, 'code', frelativepath, 0, encode(i.group(1)))
out = [["module","type","name","res_id","src","value"]] # header
# translate strings marked as to be translated
for module, type, name, id, source in _to_translate:
trans = trans_obj._get_source(cr, uid, name, type, lang, source)
out.append([module, type, name, id, source, trans or ''])
out.append([module, type, name, id, source, encode(trans) or ''])
from pprint import pformat
netsvc.Logger().notifyChannel('translation', netsvc.LOG_DEBUG, pformat(filter(lambda o:any(isinstance(x, unicode) for x in o), out)))
cr.close()
return out
@@ -492,7 +507,7 @@ def trans_load(db_name, filename, lang, strict=False, verbose=True):
return r
except IOError:
if verbose:
logger.notifyChannel("init", netsvc.LOG_ERROR, "couldn't read translation file %s" % (filename,)) # FIXME translate message
logger.notifyChannel("init", netsvc.LOG_ERROR, "couldn't read translation file %s" % (filename,))
return None
def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=None, verbose=True):
+9 -2
View File
@@ -113,15 +113,22 @@ class interface(netsvc.Service):
if lang:
# translate fields
for field in fields:
trans = translate(cr, self.wiz_name+','+state+','+field, 'wizard_field', lang)
res_name = "%s,%s,%s" % (self.wiz_name, state, field)
trans = translate(cr, res_name, 'wizard_field', lang)
if trans:
fields[field]['string'] = trans
if 'selection' in fields[field]:
trans = lambda x: translate(cr, self.wiz_name+','+state+','+field, 'selection', lang, x) or x
trans = lambda x: translate(cr, res_name, 'selection', lang, x) or x
for idx, (key, val) in enumerate(fields[field]['selection']):
fields[field]['selection'][idx] = (key, trans(val))
if 'help' in fields[field]:
t = translate(cr, res_name, 'help', lang, fields[field]['help'])
if t:
fields[field]['help'] = t
# translate arch
if not isinstance(arch, UpdateableStr):
doc = dom.minidom.parseString(arch)