summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kersten <jke@odoo.com>2015-01-30 14:03:10 +0100
committerJeremy Kersten <jke@odoo.com>2015-01-30 14:26:48 +0100
commit4a698da8b37055922be75a85f76d750dfbbadd42 (patch)
tree04d210c8a34fb0f41ec5fd0bcc2f646f8a9bdec7
parent67443b5b176731e7ba45236034e5ec3ab56b43a9 (diff)
[IMP] qweb: Allow to propagate value to variables outside the loop.
If the variable was existing outside the context of the ``foreach``, the value is copied at the end of the foreach into the global context. Fix #4461 - Q74531 - Q71486 - Q71675
-rw-r--r--addons/web/static/lib/qweb/qweb2.js4
-rw-r--r--doc/reference/qweb.rst20
-rw-r--r--openerp/addons/base/ir/ir_qweb.py4
3 files changed, 28 insertions, 0 deletions
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index 2fbef19000a..92139b3c483 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -187,6 +187,10 @@ var QWeb2 = {
}
}
}
+
+ _.each(Object.keys(old_dict), function(z) {
+ old_dict[z] = new_dict[z];
+ });
} else {
this.exception("No enumerator given to foreach", context);
}
diff --git a/doc/reference/qweb.rst b/doc/reference/qweb.rst
index a7564ded394..30ef4c25196 100644
--- a/doc/reference/qweb.rst
+++ b/doc/reference/qweb.rst
@@ -158,6 +158,26 @@ variables for various data points:
a boolean flag indicating that the current iteration round is on an odd
index
+
+These extra variables provided and all new variables created into the
+``foreach`` are only available in the scope of the``foreach``. If the
+variable exists outside the context of the ``foreach``, the value is copied
+at the end of the foreach into the global context.
+
+::
+
+ <t t-set="existing_variable" t-value="False"/>
+ <!-- existing_variable now False -->
+
+ <p t-foreach="[1, 2, 3]" t-as="i">
+ <t t-set="existing_variable" t-value="True"/>
+ <t t-set="new_variable" t-value="True"/>
+ <!-- existing_variable and new_variable now True -->
+ </p>
+
+ <!-- existing_variable always True -->
+ <!-- new_variable undefined -->
+
.. _reference/qweb/attributes:
attributes
diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py
index 4e8d60d0256..e28eebcc6d1 100644
--- a/openerp/addons/base/ir/ir_qweb.py
+++ b/openerp/addons/base/ir/ir_qweb.py
@@ -414,6 +414,10 @@ class QWeb(orm.AbstractModel):
'%s_odd' % varname: False,
})
ru.append(self.render_element(element, template_attributes, generated_attributes, copy_qwebcontext))
+
+ for k in qwebcontext.keys():
+ qwebcontext[k] = copy_qwebcontext[k]
+
return "".join(ru)
def render_tag_if(self, element, template_attributes, generated_attributes, qwebcontext):