تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
11706 أدوات العرض

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
يوليو 17
2920
0
مارس 15
2713
2
مارس 15
16866
0
سبتمبر 17
10414
1
مايو 25
378