[FIX] base: do not duplicate spaces for t-foreach

The duplication was used to have a cleaner html page source code by
aligning the <script t-foreach/> for example. However, this behavior
seems difficult to understand and use. Additionally the behavior can be
done with a <t> tag and placing the script inside.

From now on, the space "trick" is only done for <t> tags, so the
template fragment

    <article t-foreach="[0, 1, 2]" t-as="value" t-esc="value"/>
    <t t-foreach="[0, 1, 2]" t-as="value">
        <article t-esc="value"/>
    </t>

renders as

    <article>0</article><article>1</article><article>2</article>
        <article>0</article>
        <article>1</article>
        <article>2</article>

closes odoo/odoo#86695

X-original-commit: 8f817790d3f36455c66647e79df40b7173ac498a
Signed-off-by: Raphael Collet <rco@odoo.com>
This commit is contained in:
Gorash
2022-03-18 20:40:41 +01:00
committed by Raphael Collet
parent f5ff26f42e
commit 816e2eb8a6
2 changed files with 30 additions and 9 deletions
+3 -5
View File
@@ -1655,14 +1655,12 @@ class IrQWeb(models.AbstractModel):
if not VARNAME_REGEXP.match(expr_as):
raise ValueError(f'The varname {expr_as!r} can only contain alphanumeric characters and underscores.')
if el.tag.lower() == 't':
self._rstrip_text(options)
strip = self._rstrip_text(options)
code = self._flush_text(options, level)
content_foreach = []
if strip and el.tag.lower() != 't':
self._append_text(strip, options)
content_foreach.extend(
content_foreach = (
self._compile_directives(el, options, level + 1) +
self._flush_text(options, level + 1, rstrip=True))
+27 -4
View File
@@ -1538,7 +1538,32 @@ class TestQWebBasic(TransactionCase):
self.assertEqual(str(rendered).strip(), result.strip())
def test_space_remove_technical_space(self):
def test_space_remove_technical_space_t_foreach(self):
view = self.env['ir.ui.view'].create({
'name': 'master',
'type': 'qweb',
'arch_db': '''<t t-name='master'>
<section>
<article t-foreach="[0, 1, 2]" t-as="value" t-esc="value"/>
<t t-foreach="[0, 1, 2]" t-as="value">
<article t-esc="value"/>
</t>
</section>
</t>'''})
result = '''
<section>
<article>0</article><article>1</article><article>2</article>
<article>0</article>
<article>1</article>
<article>2</article>
</section>'''
rendered = self.env['ir.qweb']._render(view.id)
self.assertEqual(str(rendered), result)
def test_space_remove_technical_all(self):
test = self.env['ir.ui.view'].create({
'name': 'test',
'type': 'qweb',
@@ -1622,8 +1647,7 @@ class TestQWebBasic(TransactionCase):
<article>
<div>
<span>0</span>
</div>
<div>
</div><div>
<span>1</span>
</div>
@@ -1638,7 +1662,6 @@ class TestQWebBasic(TransactionCase):
</section>'''
rendered = self.env['ir.qweb']._render(view.id)
self.assertEqual(str(rendered), result)
class FileSystemLoader(object):