Hi Anthony,

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? 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], ...)? Another stupid 
question - what's difference between request.args[:1] and request.args(0)?j

Since i want to allow enduser to type in 
http://localhost/tests/default/view_invoices without args for selecting all 
invoices, what do you suggest I should do? I tried below (not sure if it's 
what you meant ... conditionally set the "args" argument of the smartgrid) , 
but same issue happened. Many thanks for all your pointers.

def view_invoices():
    customer_id = request.args(0)
    if customer_id:
        invoice_query=db.invoice.customer==customer_id
        constraints=dict(invoice=invoice_query)
        invoice_grid = SQLFORM.smartgrid(db.invoice, args=request.args[:1], 
constraints=constraints, linked_tables=dict(invoice=['item'], item=[]))
    else:
        invoice_query=db.invoice.customer!=None
        constraints=dict(invoice=invoice_query)
        invoice_grid = SQLFORM.smartgrid(db.invoice, 
constraints=constraints, linked_tables=dict(invoice=['item'], item=[]))
    return locals()



On Tuesday, April 4, 2017 at 8:31:25 PM UTC+8, Anthony wrote:
>
> here is the minimal app, and I did reproduce the problem and narrowed 
>> where it broke. 
>> In view_invoices() action, it checks if customer id args is provided, if 
>> so it will take it in for invoice_query = db.invoice.customer==customer_id, 
>> if not invoice_query = db.invoice.customer != None (pls let me know if 
>> there is a better way to define the query for selecting all invoice). Below 
>> code works when I specify the customer id in the URL eg. 
>> http://localhost:8000/tests/default/view_invoices/2, now when i click on 
>> the linked_tables 'Items', it will redirect to 
>> http://localhost:8000/tests/default/view_invoices/2/invoice/item.invoice/1
>> . 
>> Now, if I don't specify the customer id in URL
>>
>
> That's the problem. In some cases you don't specify the customer ID as 
> request.args[0], and yet in all cases you tell smartgrid that you are in 
> fact using request.args[0] (by specifying args=request.args[:1]). You must 
> either always specify something as the first URL arg in your links, or 
> conditionally set the "args" argument of the smartgrid.
>  
>
>> Another question related to it is - how does web2py construct the URL for 
>> redirect when linked_tables is used? eg. 
>> http://localhost:8000/tests/default/view_invoices/2
>> /invoice/item.invoice/1. The blue part is what I typed in, the red is 
>> provided by the linked_tables.
>>
>
> The grid generates a number of different links and uses the URL args 
> (after any you explicitly specify) to determine what output to generate. 
> For example, the above indicates you started viewing records in the invoice 
> table and then clicked a link pointing to records in the item table with a 
> db.item.invoice value of 1 (i.e., items linked to invoice 1).
>
> 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