Unable to redirect to another page from ondelete

50 views
Skip to first unread message

João Matos

unread,
Mar 10, 2019, 10:20:39 AM3/10/19
to web2py-users
Hello,

I'm unable to redirect to another page from a grid's ondelete.
I have this grid in the index function of a controller

        grid: DIV = SQLFORM.grid(
            db.client, csv=False, details=False,
            # noconfirm=True,  # Grid only.
            ondelete=on_delete,  # Grid only.
            onvalidation=on_validation,  # Form only.
            orderby=db.client.name,
            paginate=session.auth.user.pagination,
            # represent_none='',  # Grid/view form only.
            searchable=False,
        )

and the on_delete function is this

@auth.requires(lambda: (auth.is_logged_in() and request.env.http_referer
                        and '/client' in request.env.http_referer))
def on_delete(table, rec_id):
    # type: (pydal.objects.Table, str) -> None
    """Grid delete button action (does not redirect to other pages).

    :param table: Table.
    :param rec_id. Record id.
    """
    row: pydal.objects.Row = table(rec_id)
    row.update_record(cancel_approved_by=auth.user_id, canceled_by=auth.user_id,
                               canceled_on=request.now, is_active=False)
    session.flash = T('Press F5 to refresh.')
    redirect(URL(user_signature=True))

That works.

However, if I change the redirection to another page, eg.


    redirect(URL('diff_page', user_signature=True))

or even another page in a different controller

    redirect(URL('default', 'index', user_signature=True))

the redirection doesn't work and there is no error.

Is this behaviour correct?

If I do the same in the grid's onvalidation, the redirection works.

Thanks,

JM

jcrm...@gmail.com

unread,
May 3, 2019, 8:30:29 AM5/3/19
to web2py-users
Have to use redirect(URL(..), client_side=True)
Reply all
Reply to author
Forward
0 new messages