[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
This commit is contained in:
Jeremy Kersten 2015-01-30 14:03:10 +01:00
parent 67443b5b17
commit 4a698da8b3
3 changed files with 28 additions and 0 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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):