From e6b91f0a69600bcf5d8ad12be999a9d83a72eb55 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 8 Mar 2012 18:43:04 +0100 Subject: [PATCH] [FIX] correct XML generation to avoid bad surprise (as ampersand in application name) to break the code. bzr revid: valentin.lab@kalysto.org-20120308174304-3oqewchzlxw0fdre --- openerp/addons/base/res/res_users.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index f148813ae05..2617efeb4a2 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -34,6 +34,9 @@ from service import security from tools.translate import _ import openerp import openerp.exceptions +from lxml import etree +from lxml.builder import E + _logger = logging.getLogger(__name__) @@ -743,29 +746,27 @@ class groups_view(osv.osv): # and introduces the reified group fields view = self.get_user_groups_view(cr, uid, context) if view: - xml = u""" - - -%s -%s - -""" + xml1, xml2 = [], [] - xml1.append('' % _('Applications')) + xml1.append(E.separator(string=_('Application'), colspan="4")) for app, kind, gs in self.get_groups_by_application(cr, uid, context): if kind == 'selection': # application name with a selection field field_name = name_selection_groups(map(int, gs)) - xml1.append('' % field_name) - xml1.append('') + xml1.append(E.field(name=field_name)) + xml1.append(E.newline()) else: # application separator with boolean fields app_name = app and app.name or _('Other') - xml2.append('' % app_name) + xml2.append(E.separator(string=app_name, colspan="4")) for g in gs: field_name = name_boolean_group(g.id) - xml2.append('' % field_name) - view.write({'arch': xml % ('\n'.join(xml1), '\n'.join(xml2))}) + xml2.append(E.field(name=field_name)) + + xml = E.field(*(xml1 + xml2), name="groups_id", position="replace") + xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) + xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") + view.write({'arch': xml_content}) return True def get_user_groups_view(self, cr, uid, context=None):