[FIX] avoid losing non-meta attributes when converting t-fields back

bzr revid: xmo@openerp.com-20130919092546-c7yr8e4kixh4ngta
This commit is contained in:
Xavier Morel 2013-09-19 11:25:46 +02:00
parent e0662b11d0
commit 5de155ad98
2 changed files with 18 additions and 3 deletions

View File

@ -80,6 +80,18 @@ class TestViewSaving(common.TransactionCase):
h.SPAN({'t-field': 'bob'})
)
def test_to_field_ref_keep_attributes(self):
View = self.registry('ir.ui.view')
att = attrs(expression="bob", model="res.company", id=1, field="name")
att['id'] = "whop"
att['class'] = "foo bar"
embedded = h.SPAN("My Company", att)
self.eq(View.to_field_ref(self.cr, self.uid, embedded, context=None),
h.SPAN({'t-field': 'bob', 'class': 'foo bar', 'id': 'whop'}))
def test_replace_arch(self):
replacement = h.P("Wheee")

View File

@ -102,9 +102,12 @@ class view(osv.osv):
}, context=context)
def to_field_ref(self, cr, uid, el, context=None):
out = html.html_parser.makeelement(el.tag, attrib={
't-field': el.get('data-oe-expression'),
})
# filter out meta-information inserted in the document
attributes = dict((k, v) for k, v in el.items()
if not k.startswith('data-oe-'))
attributes['t-field'] = el.get('data-oe-expression')
out = html.html_parser.makeelement(el.tag, attrib=attributes)
out.tail = el.tail
return out