Anthony,

I can't thank you enough for all your advises and help, not only i 
understand more about the grid / smartgrid, but the use of request.args 
now. I appreciate a lot of your time. Rudy

On Thursday, April 6, 2017 at 2:57:00 AM UTC+8, Anthony wrote:
>
> Pardon me for asking stupid question, what does SQLFORM.smartgrid(....., 
>> args=request.args[:1], ...) really do? you mentioned in earlier post that 
>> args must be a list, and it preserves the 1st argument of URL for 
>> application specific use. Does it tell web2py whatever url it creates, it 
>> should always preserve the same URL up to the 1st argument (for this case) 
>> eg. http://localhost/tests/default/view_invoices/2?
>>
>
> The grid builds its own internal URLs by taking the base URL of the action 
> that serves the grid and adding URL args. If you specify the "args" 
> parameter, it will first add any args from that to the URL before adding 
> any of its own args, thus preserving any args you are using for non-grid 
> purposes.
>  
>
>> I looked up the documentation, there is little info about args in grid / 
>> smartgrid signature. If above assumption is correct, if my applications 
>> uses first 2 args for specific application purpose, i should modify the 
>> code to SQLFORM.smartgrid(....., args=request.args[:2], ...)?
>>
>
> Correct.
>  
>
>> Another stupid question - what's difference between request.args[:1] and 
>> request.args(0)?
>>
>
> The former produces a list (even if it contains zero items or one item), 
> whereas the latter returns an individual value.
>
> def view_invoices():
>>     customer_id = request.args(0)
>>     if customer_id:
>>
>
> This is not a helpful conditional because once you click on any link 
> produced by the grid, there will always be some value for request.args(0) 
> (because the grid will have added some URL args to the URLs it generates). 
> One option is something like:
>
>     customer_id = request.args(0, cast=int, otherwise=lambda: None)
>     if customer_id is not None:
>
> The above will attempt to cast the first URL arg to an int and return None 
> otherwise. The grid doesn't use ints as the first URL arg, so if the above 
> returns None, that means there is no URL arg or it is not an int, which 
> implies that no customer_id has been specified.
>
> 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