[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:
parent
857e7a4f56
commit
29707bb8bf
|
@ -74,12 +74,10 @@ class TestViewSaving(common.TransactionCase):
|
||||||
|
|
||||||
def test_embedded_to_field_ref(self):
|
def test_embedded_to_field_ref(self):
|
||||||
View = self.registry('ir.ui.view')
|
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(
|
self.eq(
|
||||||
View.to_field_ref(self.cr, self.uid, embedded, context=None),
|
View.to_field_ref(self.cr, self.uid, embedded, context=None),
|
||||||
h.SPAN({'t-field': 'registry[%r].browse(cr, uid, %r).%s' % (
|
h.SPAN({'t-field': 'bob'})
|
||||||
'res.company', 1, 'name'
|
|
||||||
)})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_replace_arch(self):
|
def test_replace_arch(self):
|
||||||
|
@ -127,8 +125,8 @@ class TestViewSaving(common.TransactionCase):
|
||||||
h.H3("Column 2"),
|
h.H3("Column 2"),
|
||||||
h.UL(
|
h.UL(
|
||||||
h.LI("wob wob wob"),
|
h.LI("wob wob wob"),
|
||||||
h.LI(h.SPAN("Acme Corporation", attrs(model='res.company', id=1, field='name'))),
|
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'))),
|
h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone', expression="edmund"))),
|
||||||
)
|
)
|
||||||
), encoding='utf-8')
|
), encoding='utf-8')
|
||||||
View.save(self.cr, self.uid, res_id=self.view_id, value=replacement,
|
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.H3("Column 2"),
|
||||||
h.UL(
|
h.UL(
|
||||||
h.LI("wob wob wob"),
|
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': "bob"})),
|
||||||
h.LI(h.SPAN({'t-field': "registry['res.company'].browse(cr, uid, 1).phone"}))
|
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"),
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -63,14 +63,11 @@ class view(osv.osv):
|
||||||
}, context=context)
|
}, context=context)
|
||||||
|
|
||||||
def to_field_ref(self, cr, uid, el, context=None):
|
def to_field_ref(self, cr, uid, el, context=None):
|
||||||
# FIXME: better ref?
|
out = html.html_parser.makeelement(el.tag, attrib={
|
||||||
return html.html_parser.makeelement(el.tag, attrib={
|
't-field': el.get('data-oe-expression'),
|
||||||
'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.tail = el.tail
|
||||||
|
return out
|
||||||
|
|
||||||
def replace_arch_section(self, cr, uid, view_id, section_xpath, replacement, context=None):
|
def replace_arch_section(self, cr, uid, view_id, section_xpath, replacement, context=None):
|
||||||
arch = replacement
|
arch = replacement
|
||||||
|
|
Loading…
Reference in New Issue