Hi Przemyslaw, I am forwarding your email to the mailing list since this issues are probably of general interest.
request.function is always the function requested by the browser in the URL. When your program calls redirect, it tells the browser to request the other page. If you want to know which page causes the redirect you can use request.env.http_referrer (but that is browser dependent) or you can do: > def first(): > form = FORM( > INPUT(_name='visitor_name', requires=IS_NOT_EMPTY()), > INPUT(_type='submit') > ) > if request.vars.visitor_name: > session.visitor_name = request.vars.visitor_name > redirect(URL(r=request, > f='second',vars=dict(referrer='first')) ### here > return dict(form=form) > > def second(): > print request.function, session.visitor_name # request.function > is always 'second' request.vars.referrer == 'first' ### here > redirect(URL(r=request, f='first')) > return dict() About your second question. I am not sure what you mean by "before" and "after".but you can define a form outside a function so that it can be reused in multiple functions: > myform = FORM( > INPUT(_name='visitor_name', requires=IS_NOT_EMPTY()), > INPUT(_type='submit') > ) > > def first_after(): > if myform.accepts(request.vars): > session.visitor_name = request.vars.visitor_name > redirect(URL(r=request, f='second')) > else : > redirect(URL(r=request, f='some_error_page')) return dict(form=myform) I am not sure I answered your questions. Massimo On Dec 28, 2009, at 9:06 AM, pdp83 wrote: > Hello, > > I've started playing with web2py few day ago and encounter a > behavior that I don't understand and seems to me that it might be a > bug. Sorry to spam you if it isn't and please simply ignore this > mail in that case. > > version: > 1.74.4 windows > description: > I can't tell what controller I came from in 'second()' function > because request.function always returns 'second' > Here is a modified example from the book: > > def first(): > form = FORM( > INPUT(_name='visitor_name', requires=IS_NOT_EMPTY()), > INPUT(_type='submit') > ) > if request.vars.visitor_name: > session.visitor_name = request.vars.visitor_name > redirect(URL(r=request, f='second')) > return dict(form=form) > > def second(): > print request.function, session.visitor_name # request.function > is always 'second' > if not request.function=='first' and not session.visitor_name: > # this doesn't enter the condition because > session.visitor_name is not empty, > # I'm also guessing there should be 'or' instead of 'and' > redirect(URL(r=request, f='first')) > return dict() > ------------ > I have one more question, is there a way to split execution of > controller to before and after page is loaded/submited so that form > gets created only once? > > def first_before(): > form = FORM( > INPUT(_name='visitor_name', requires=IS_NOT_EMPTY()), > INPUT(_type='submit') > ) > return dict(form=form) > > def first_after(): > if request.vars.visitor_name: > session.visitor_name = request.vars.visitor_name > redirect(URL(r=request, f='second')) > else : > redirect(URL(r=request, f='some_error_page')) > > > With Best Regards, > Przemyslaw Podczasi > > ps. Awesome framework and a Happy New Year! -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.