On 19 May 2014 07:34, Sarbjit <[email protected]> wrote:
I am facing problem using GRID, the results which are displayed in the gird
> are correct as per query but if the number of records are more, then
> results are displayed across multiple pages in the grid. Problem is that
> when, I select second (any other page) to view more results from grid, i
> get the error that "local variable grid is referenced before assignment".
> Can some one please help me on how to resolve this. (I actually have to
> build grid on another page)
>
>
> *Controller :*
> def results():
> query = (db.Products.product_version==request.vars.product_name))
> if request.vars.product_name and request.vars.makers_name:
> grid =
> SQLFORM.grid(query=query,csv=False,create=False,deletable=False,)
> return dict(grid=grid)
>
> On the next page there is no 'request.vars.product_name and
request.vars.makers_name' so the line defining your grid is not executed
and when the function tries to return 'grid' it is trying to return
something that has not been assigned.
If you need the 'if' statement, then you can create session variables from
the request.vars and use that for the next page.
Something like this (untested).
def results():
if not session.product_name:
session.product_name = request.vars.product_name
if not session.makers_name:
session.makers_name = request.vars.product_name
query = (db.Products.product_version== session.product_name))
if session.product_name and session.makers_name:
grid =
SQLFORM.grid(query=query,csv=False,create=False,deletable=False,)
return dict(grid=grid)
And then you will have to get rid of the session variables before
attempting your next query --> grid.
There are probably better ways to handle the condition in your function
like checking it earlier and eliminating the 'if' in your grid definition.
Regards
Johann
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.