Skip to Content
Menu
This question has been flagged
1 Reply
11918 Views

How we can update dictionary in python ?

"update" key is not working in qweb.

<t t-set="my_dict" t-value="{}"/>
<t t-foreach="['name'] t-as="key">
    <t t-foreach="['abc', 20] t-as="value">
        <t t-set="my_dict" t-value="my_dict.update({key:value})"/>
    </t>
</t>
<span t-esc="my_dict"/>

my_dict is display none.

Avatar
Discard

you should write the function the python code and call it back in the xml Example: - python: from openerp.report import report_sxw from openerp.osv import osv class example_class(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(sale_common, self).__init__( cr, uid, name, context=context) self.localcontext.update({ 'update_your_dict': self.update_your_dict }) def update_your_dict(self, o): # your source code here return true - xml: Demo Function Python:

Author

Thanks Anh Vu But I have to do in xml file not in py file.

Best Answer

dict.update() updates the dictionay in place, and returns None.

dictA | dictB returns a union of both dictA and dictB, but it looks like Qweb ignores it.

I've been able to update a dictionary with this:


(see comment for code as this forum won't let me post code at the moment)

__ is just a phony variable to get the t-value directive to actually evaluate.

Avatar
Discard

<t t-set="__" t-value="my_dict[key] = value"/>

oh my god this forum's tools to write code in replies suck so bad! :O I'm so sorry for what the answer looks like :(

Author

Hi Jérôme Thériault,

<t t-set="my_dict" t-value="{}"/>
<t t-foreach="['name'] t-as="key">
<t t-foreach="['abc', 20] t-as="value">
<t t-esc="my_dict.update({key:value})"/>
</t>
</t>
<span t-esc="my_dict"/>

It's working well to prepare and update the dict.

Related Posts Replies Views Activity
1
Apr 25
1176
2
Mar 25
1312
4
Nov 24
7042
1
Mar 24
1957
3
Sep 23
24741