You both are righ:
What's work now (also should worke before):
selectable=[('change price 100', lambda ids: modify_price(ids,100) ), ]

and the function in the same controller:
def modify_price(ids,inc):

print request.vars.records
print ids
print inc 


Both request.vars.records and ids are lists also with only one selected

Thanks for help  

 








On Sunday, April 21, 2019 at 1:56:09 AM UTC+2, Anthony wrote:
>
> On Saturday, April 20, 2019 at 8:52:01 AM UTC-4, icodk wrote:
>>
>> Hi Antony
>>
>> My selectable looks like :
>>
>> selectable = [('Add 100 to price',lambda ids: redirect(URL('product', 
>> 'modify_price', args=request.args, vars=dict(id=ids, inc=100)))),
>>
>>
> Why do a redirect rather than simply doing the work in the same function? 
> Also, this redirect puts the ids in the URL query string, resulting in the 
> ultimate update being a GET request rather than a POST -- this is 
> undesirable because a refresh of that page will result in the entire 
> operation being repeated, which you don't want.
>  
>
>>
>> and my function in the product controller looks like this:
>>
>> def modify_price():
>>
>> if type(request.vars.id) is str:
>>
>>     id_list = request.vars.id.split(',') #convertint to list
>>
>> else:
>>
>>     id_list = request.vars.id
>>
>> db(db.product.id.belongs(id_list)).update(product_price=db.product.product_price+request.vars.inc)
>>
>>
>>  Simply following the documentation in the book
>>
>> I also tried:
>>
>> selectable=  lambda ids: modify_price
>>
>>
>> But the function neve called
>>
>
> It's not that the function never gets called but that the function is not 
> written to work this way. The function expects to find ids in 
> request.vars.id, but that is actually None in the case where you call it 
> this way (the real values are in request.vars.records). Is modify_price a 
> controller action that needs to be accessible separately from this 
> particular operation? If not, just make it a helper function that accepts 
> an "ids" argument, and set selectable=modify_price.
>
> Anthony
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to