Here is a test function in my controller: 

def test():
    id = 0
    try:
        id = request.args(0, cast=int)
        session.flash = "Here is the id: " + str(id)
    except:
        session.flash = "ID is not valid!"
        pass
    if id==0:
        redirect(URL('home'))
    query = db.test_table.id == id
    grid = SQLFORM.grid(query, db.test_table, user_signature=False)
    return locals()

Here are issues I've encountered with this (not sure if they are 
independent or related): 

1) the flash msg displays the previously passed parameters, not the latest 
one. This is weird! For example, app/home/test/1 called the first time does 
NOT display any flash msg at all.  When I call it the 2nd time - 
app/home/test/2 - the flash message displays "1", i.e. previously called 
number. At the same time, the page displays correctly - the page knows that 
the correct number is 2 indeed now. 

2) The grid behaves very strangely. Here is how: when I delete a record, 
the page silently reloads (I know this because of the flash message - which 
displays the previous id, not the current one), and in case this is my 
first call to this page, it comes out that ID is not valid and id equals 0 
EVEN THOUGH I passed the parameter through vars (app/home/test/1) it breaks 
the delete - delete never commits to the database. It does delete the row 
from the grid thought, so visually the row is gone, but the database is not 
altered. At the same time, if I remove that redirect('home') - the delete 
completes and commits to the database just fine (i.e. as long as redirect 
is not there - even though this strange reloading of the page is going on - 
it doesn't bother me - the messed up parameter only causes redirect which 
somehow breaks the delete). 

Namely, the following code (same but without redirect): 

def test():
    id = 0
    try:
        id = request.args(0, cast=int)
        session.flash = "Here is the id: " + str(id)
    except:
        session.flash = "ID is not valid!"
        pass
    query = db.test_table.id == id
    grid = SQLFORM.grid(query, db.test_table, user_signature=False)
    return locals()

still doesn't display flash msgs correctly, BUT it does not break grid's 
functionality - delete completes (can't fathom how this could be, as if 
request.var is incorrect - then the page should display incorrectly, but if 
request.var is somehow correct then redirect should never happen to begin 
with, how can it influence anything? And if redirect is actually called 
(and it is) on grid's delete operation, it means that the id is now 
incorrect, why doesn't it break the view of the page?? I am totally 
confused...

I hope this doesn't sound messy :) I've been going crazy for a while until 
I've isolated what I've just described... 

And, by the way, the app logic I am trying to achieve is simple: I pass the 
param through request.vars but then first check if the current user is 
authorized, and if not - I redirect. I need some custom authorization logic 
here, so usual auth decorates don't help in my situation.

3) this is more of a side issues, but I'll mention it, as I am on the grid: 
in some situations grids work just fine without user_signature=False , but 
sometimes they refuse and display error msgs like not authorized etc. I 
can't detect the difference when it's needed. This is not a big deal, I can 
just place user_signature=False whenever, but it does bother me, since I 
don't understand what exactly is causing this difference that breaks the 
functionality in some situations. 

Any suggestions are greatly appreciated.... 
 

-- 
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