跳至内容
菜单
此问题已终结
4 回复
11957 查看

I'm trying to update context from within class DataSet(http.Controller) (web module)


I want the do_search_read method to change the context of the caller. However, although everything seems to be fine, the context is not updated.


Here's my code:


if model == 'mymodel':

     request.context['result_ids'] = [x.product_tmpl_id.id for x in Model.browse(aux)]

 

request.context is, indeed, updated but the caller's context remains the same.

形象
丢弃
编写者

NOTE: I've already tried the "antidote" to the "frozen dictionary" problem.

The code here is just that an example.

最佳答案

Hello Rui Franco

context is a frozen dictionary. so, we can not directly change.

you can try this.    

     request.with_context({'result_ids':[x.product_tmpl_id.id for x in Model.browse(aux)]})


Hope this help.

形象
丢弃
编写者

Thanks but it won't work:

AttributeError: 'JsonRequest' object has no attribute 'with_context'

最佳答案

ctx = dict (request.context)


ctx.update ({'bin_size': True})


request.context = ctx


Thats it!!

形象
丢弃

ctx = (request.context.copy())

ctx.update(lang=ticket.partner_id.lang)

request.context = ctx

相关帖文 回复 查看 活动
0
7月 17
3090
0
3月 15
2869
2
3月 15
17055
0
9月 17
10604
1
5月 25
703