[MERGE] Forward-port latest bugfixes from 8.0 up to cbb51610ee

This commit is contained in:
Olivier Dony
2015-02-24 14:47:19 +01:00
6 changed files with 77 additions and 47 deletions
+5 -39
View File
@@ -221,49 +221,15 @@ class Website(openerp.addons.web.controllers.main.Home):
``full=True`` returns inherit view's informations of the template ``key``.
``bundles=True`` returns also the asset bundles
"""
imd = request.registry['ir.model.data']
view_model, view_theme_id = imd.get_object_reference(
request.cr, request.uid, 'website', 'theme')
user = request.registry['res.users']\
.browse(request.cr, request.uid, request.uid, request.context)
user_groups = set(user.groups_id)
views = request.registry["ir.ui.view"]\
._views_get(request.cr, request.uid, key, bundles=bundles, context=dict(request.context or {}, active_test=False))
done = set()
result = []
for v in views:
if not user_groups.issuperset(v.groups_id):
continue
if full or (v.customize_show and v.inherit_id.id != view_theme_id):
if v.inherit_id not in done:
result.append({
'name': v.inherit_id.name,
'id': v.id,
'key': v.key,
'inherit_id': v.inherit_id.id,
'header': True,
'active': False
})
done.add(v.inherit_id)
result.append({
'name': v.name,
'id': v.id,
'key': v.key,
'inherit_id': v.inherit_id.id,
'header': False,
'active': v.active,
})
return result
return request.registry["ir.ui.view"].customize_template_get(
request.cr, request.uid, key, full=full, bundles=bundles,
context=request.context)
@http.route('/website/get_view_translations', type='json', auth='public', website=True)
def get_view_translations(self, xml_id, lang=None):
lang = lang or request.context.get('lang')
views = self.customize_template_get(xml_id, full=True)
views_ids = [view.get('id') for view in views if view.get('active')]
domain = [('type', '=', 'view'), ('res_id', 'in', views_ids), ('lang', '=', lang)]
irt = request.registry.get('ir.translation')
return irt.search_read(request.cr, request.uid, domain, ['id', 'res_id', 'value','state','gengo_translation'], context=request.context)
return request.registry["ir.ui.view"].get_view_translations(
request.cr, request.uid, xml_id, lang=lang, context=request.context)
@http.route('/website/set_translations', type='json', auth='public', website=True)
def set_translations(self, data, lang):
+48
View File
@@ -253,3 +253,51 @@ class view(osv.osv):
view = self.browse(cr, SUPERUSER_ID, res_id, context=context)
if view.model_data_id:
view.model_data_id.write({'noupdate': True})
def customize_template_get(self, cr, uid, key, full=False, bundles=False):
""" Get inherit view's informations of the template ``key``. By default, only
returns ``customize_show`` templates (which can be active or not), if
``full=True`` returns inherit view's informations of the template ``key``.
``bundles=True`` returns also the asset bundles
"""
imd = request.registry['ir.model.data']
view_model, view_theme_id = imd.get_object_reference(
cr, uid, 'website', 'theme')
user = request.registry['res.users'].browse(cr, uid, request.context)
user_groups = set(user.groups_id)
views = self._views_get(
cr, uid, key, bundles=bundles,
context=dict(request.context or {}, active_test=False))
done = set()
result = []
for v in views:
if not user_groups.issuperset(v.groups_id):
continue
if full or (v.customize_show and v.inherit_id.id != view_theme_id):
if v.inherit_id not in done:
result.append({
'name': v.inherit_id.name,
'id': v.id,
'key': v.key,
'inherit_id': v.inherit_id.id,
'header': True,
'active': False
})
done.add(v.inherit_id)
result.append({
'name': v.name,
'id': v.id,
'key': v.key,
'inherit_id': v.inherit_id.id,
'header': False,
'active': v.active,
})
return result
def get_view_translations(self, cr, uid, xml_id, lang, field=['id', 'res_id', 'value', 'state', 'gengo_translation'], context=None):
views = self.customize_template_get(cr, uid, xml_id, full=True, context=context)
views_ids = [view.get('id') for view in views if view.get('active')]
domain = [('type', '=', 'view'), ('res_id', 'in', views_ids), ('lang', '=', lang)]
irt = request.registry.get('ir.translation')
return irt.search_read(cr, uid, domain, field, context=context)
+6 -2
View File
@@ -314,7 +314,11 @@ class ir_translation(osv.osv):
source = tools.ustr(source)
params = (lang or '', types, source, source)
if res_id:
query += " AND res_id=%s"
if isinstance(res_id, (int, long)):
res_id = (res_id,)
else:
res_id = tuple(res_id)
query += " AND res_id in %s"
params += (res_id,)
if name:
query += " AND name=%s"
@@ -341,7 +345,7 @@ class ir_translation(osv.osv):
:param types: single string defining type of term to translate (see ``type`` field on ir.translation), or sequence of allowed types (strings)
:param lang: language code of the desired translation
:param source: optional source term to translate (should be unicode)
:param res_id: optional resource id to translate (if used, ``source`` should be set)
:param res_id: optional resource id or a list of ids to translate (if used, ``source`` should be set)
:rtype: unicode
:return: the request translation, or an empty unicode string if no translation was
found and `source` was not passed
+17 -4
View File
@@ -1022,10 +1022,9 @@ class view(osv.osv):
for attr in node.attrib
)
def translate_qweb(self, cr, uid, id_, arch, lang, context=None):
def _translate_qweb(self, cr, uid, arch, translate_func, context=None):
# TODO: this should be moved in a place before inheritance is applied
# but process() is only called on fields_view_get()
Translations = self.pool['ir.translation']
h = HTMLParser.HTMLParser()
def get_trans(text):
if not text or not text.strip():
@@ -1033,7 +1032,7 @@ class view(osv.osv):
text = h.unescape(text.strip())
if len(text) < 2 or (text.startswith('<!') and text.endswith('>')):
return None
return Translations._get_source(cr, uid, 'website', 'view', lang, text, id_)
return translate_func(text)
if type(arch) not in SKIPPED_ELEMENT_TYPES and arch.tag not in SKIPPED_ELEMENTS:
text = get_trans(arch.text)
@@ -1048,7 +1047,21 @@ class view(osv.osv):
if attr:
arch.set(attr_name, attr)
for node in arch.iterchildren("*"):
self.translate_qweb(cr, uid, id_, node, lang, context)
self._translate_qweb(cr, uid, node, translate_func, context)
def translate_qweb(self, cr, uid, id_, arch, lang, context=None):
view_ids = []
view = self.browse(cr, uid, id_, context=context)
if view:
view_ids.append(view.id)
if view.mode == 'primary' and view.inherit_id.mode == 'primary':
# template is `cloned` from parent view
view_ids.append(view.inherit_id.id)
Translations = self.pool['ir.translation']
def translate_func(term):
trans = Translations._get_source(cr, uid, 'website', 'view', lang, term, view_ids)
return trans
self._translate_qweb(cr, uid, arch, translate_func, context=context)
return arch
@openerp.tools.ormcache()
@@ -8,7 +8,6 @@
.oe_module_icon {
width: 80px;
height: 80px;
padding: 0 4px;
}
.oe_module_desc {
+1 -1
View File
@@ -360,7 +360,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""")
for (model, name) in cr.fetchall():
if model in registry and not registry[model].is_transient() and not isinstance(registry[model], openerp.osv.orm.AbstractModel):
_logger.warning('The model %s has no access rules, consider adding one. E.g. access_%s,access_%s,model_%s,,1,1,1,1',
_logger.warning('The model %s has no access rules, consider adding one. E.g. access_%s,access_%s,model_%s,,1,0,0,0',
model, model.replace('.', '_'), model.replace('.', '_'), model.replace('.', '_'))
# Temporary warning while we remove access rights on osv_memory objects, as they have