[FIX] don't lose text following a node being transformed back into a t-field

bzr revid: xmo@openerp.com-20130910143406-nuzu8vz5rzmshnzc
This commit is contained in:
Xavier Morel 2013-09-10 16:34:06 +02:00
parent 857e7a4f56
commit 29707bb8bf
2 changed files with 38 additions and 15 deletions

View File

@ -74,12 +74,10 @@ class TestViewSaving(common.TransactionCase):
def test_embedded_to_field_ref(self):
View = self.registry('ir.ui.view')
embedded = h.SPAN("My Company", attrs(model='res.company', id=1, field='name'))
embedded = h.SPAN("My Company", attrs(expression="bob"))
self.eq(
View.to_field_ref(self.cr, self.uid, embedded, context=None),
h.SPAN({'t-field': 'registry[%r].browse(cr, uid, %r).%s' % (
'res.company', 1, 'name'
)})
h.SPAN({'t-field': 'bob'})
)
def test_replace_arch(self):
@ -127,8 +125,8 @@ class TestViewSaving(common.TransactionCase):
h.H3("Column 2"),
h.UL(
h.LI("wob wob wob"),
h.LI(h.SPAN("Acme Corporation", attrs(model='res.company', id=1, field='name'))),
h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone'))),
h.LI(h.SPAN("Acme Corporation", attrs(model='res.company', id=1, field='name', expression="bob"))),
h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone', expression="edmund"))),
)
), encoding='utf-8')
View.save(self.cr, self.uid, res_id=self.view_id, value=replacement,
@ -150,8 +148,36 @@ class TestViewSaving(common.TransactionCase):
h.H3("Column 2"),
h.UL(
h.LI("wob wob wob"),
h.LI(h.SPAN({'t-field': "registry['res.company'].browse(cr, uid, 1).name"})),
h.LI(h.SPAN({'t-field': "registry['res.company'].browse(cr, uid, 1).phone"}))
h.LI(h.SPAN({'t-field': "bob"})),
h.LI(h.SPAN({'t-field': "edmund"}))
))
)
)
def test_field_tail(self):
View = self.registry('ir.ui.view')
replacement = ET.tostring(
h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone', expression="edmund")),
"whop whop"
), encoding="utf-8")
View.save(self.cr, self.uid, res_id = self.view_id, value=replacement,
xpath='/div/div[2]/ul/li[3]')
self.eq(
ET.fromstring(View.browse(self.cr, self.uid, self.view_id).arch.encode('utf-8')),
h.DIV(
h.DIV(
h.H3("Column 1"),
h.UL(
h.LI("Item 1"),
h.LI("Item 2"),
h.LI("Item 3"))),
h.DIV(
h.H3("Column 2"),
h.UL(
h.LI("Item 1"),
h.LI(h.SPAN("My Company", attrs(model='res.company', id=1, field='name'))),
h.LI(h.SPAN({'t-field': "edmund"}), "whop whop"),
))
)
)

View File

@ -63,14 +63,11 @@ class view(osv.osv):
}, context=context)
def to_field_ref(self, cr, uid, el, context=None):
# FIXME: better ref?
return html.html_parser.makeelement(el.tag, attrib={
't-field': 'registry[%(model)r].browse(cr, uid, %(id)r).%(field)s' % {
'model': el.get('data-oe-model'),
'id': int(el.get('data-oe-id')),
'field': el.get('data-oe-field'),
}
out = html.html_parser.makeelement(el.tag, attrib={
't-field': el.get('data-oe-expression'),
})
out.tail = el.tail
return out
def replace_arch_section(self, cr, uid, view_id, section_xpath, replacement, context=None):
arch = replacement