LOAD and redirect

164 views
Skip to first unread message

Julius Minka

unread,
Aug 5, 2010, 2:17:40 PM8/5/10
to web2py-users
Having something like this

{{=LOAD('controller','action.load',vars={},args=[],ajax=True)}}

in the layout.html
and something like this

form=SQLFORM.factory(
Field(...),
Field(...),
Field(...),
formstyle='table2cols',submit_button='Vyhľadať')
if form.accepts(request.vars, session):
redirect(URL(r=request,
f='2action',vars={'typ':typ}))


in action controlller.

It almost works, but instead of redirection to '2action', it displays
2action page in the space where previously the form was. URL is not
changed.

Is this expected behaviour?
How to correctly do real redirection to 2action page?

Julius

mdipierro

unread,
Aug 5, 2010, 6:23:34 PM8/5/10
to web2py-users
This is the intended behavior.
for now you can do
instead of

redirect(url)

use

raise HTTP(303,**{'web2py-component-
command':'document.location="%s"'%url})

mdipierro

unread,
Aug 5, 2010, 6:27:36 PM8/5/10
to web2py-users
Since we are still we are wtill writing the specs here....
should redirect be trapped (unless specified otherwise) or not (unless
specified otherwise).
So far we have the former.

Julius Minka

unread,
Aug 7, 2010, 1:13:30 PM8/7/10
to web...@googlegroups.com
Massimo,

I am not able to make it work.

Firstly, just little note, my original
url=URL(r=request, f='nehnutelnosti',vars={'typ':request.vars.typ,
'okres':request.vars.okres, 'druh':request.vars.druh})

can not be used because it returns
/app/default/nehnutelnosti.load?okres=1&typ=1&druh=2

so it probably rightly doesn't redirect to the new page.

Secondly, I tried for testing purposes to construct url 'by hand', both
versions:
1.
http://127.0.0.1:9999/app/default/nehnutelnosti?okres=1&typ=1&druh=2

2.
/app/default/nehnutelnosti?okres=1&typ=1&druh=2

Form disappears, but that is all what happens after submit.


Form looks following in the page source:
<script type="text/javascript"><!--
web2py_component("/real/default/form.load","c712094659208")
//--></script><div id="c712094659208">loading...</div>


What else could be the problem with redirection?
Julius

V Štvrtok, 5. august 2010 o 15:23 -0700, mdipierro napísal(a):

mdipierro

unread,
Aug 7, 2010, 1:20:26 PM8/7/10
to web2py-users
Is your problem the presence of the .load?

> url=URL(r=request, f='nehnutelnosti',vars={'typ':request.vars.typ, 'okres':request.vars.okres, 'druh':request.vars.druh})
> can not be used because it returns
> /app/default/nehnutelnosti.load?okres=1&typ=1&druh=2

if you you can specify URL(....,extension='html')


On Aug 7, 12:13 pm, Julius Minka <j...@minka.sk> wrote:
> Massimo,
>
> I am not able to make it work.
>
> Firstly, just little note, my original
> url=URL(r=request, f='nehnutelnosti',vars={'typ':request.vars.typ,
> 'okres':request.vars.okres, 'druh':request.vars.druh})
>
> can not be used because it returns
> /app/default/nehnutelnosti.load?okres=1&typ=1&druh=2
>
> so it probably rightly doesn't redirect to the new page.
>
> Secondly, I tried for testing purposes to construct url 'by hand', both
> versions:
> 1.http://127.0.0.1:9999/app/default/nehnutelnosti?okres=1&typ=1&druh=2

Julius Minka

unread,
Aug 7, 2010, 1:36:16 PM8/7/10
to web...@googlegroups.com
V Sobota, 7. august 2010 o 10:20 -0700, mdipierro napísal(a):

> Is your problem the presence of the .load?
>
No, that is not the main problem.

> > url=URL(r=request, f='nehnutelnosti',vars={'typ':request.vars.typ, 'okres':request.vars.okres, 'druh':request.vars.druh})
> > can not be used because it returns
> > /app/default/nehnutelnosti.load?okres=1&typ=1&druh=2
>
> if you you can specify URL(....,extension='html')

url=URL(r=request, f='nehnutelnosti', vars={'typ':request.vars.typ,
'okres':request.vars.okres, 'druh':request.vars.druh},extension='html')

not change, result is still
/app/default/nehnutelnosti.load?okres=1&typ=1&druh=2


MAIN problem is the redirect doesn't work:
if form.accepts(request.vars, session):
url="/"+request.application
+"/default/nehnutelnosti.html?okres="+request.vars.okres
+"&typ="+request.vars.typ+"&druh="+request.vars.druh


raise HTTP(303,**{'web2py-component-command':'document.location="%s"'%

url})

Julius

mdipierro

unread,
Aug 7, 2010, 1:58:41 PM8/7/10
to web2py-users
There is a problem with URL. Please check trunk and see if it solves
the problem for you:

This works for me

def index():
return dict()

def test1():
form=SQLFORM.factory(Field('name'))
if form.accepts(request.vars,session):
url = URL('test2',extension='html')
response.headers['web2py-component-
command']='document.location="%s"' % url
raise HTTP(303,**response.headers)
redirect(URL('test2'))
return dict(form=form)

def test2():
return dict(h=H1('hello world'))


with default/index.html

{{extend 'layout.html'}}
This is a test
{{=LOAD('default','test1.load',ajax=True)}}

Julius Minka

unread,
Aug 7, 2010, 3:16:43 PM8/7/10
to web...@googlegroups.com
No, redirection doesn't work for me.
Last released version I used before was Version 1.82.1 (2010-08-05
01:00:12)

I got current trunk this way:
hg clone https://web2py.googlecode.com/hg/ web2py078a
requesting all changes
adding changesets
adding manifests
adding file changes
added 764 changesets with 2180 changes to 733 files
updating to branch default
588 files updated, 0 files merged, 0 files removed, 0 files unresolved

It identifies itself as Version 1.82.1 (2010-08-04 18:57:33).
Attached you can find the application as I typed it from your email.

Julius

V Sobota, 7. august 2010 o 10:58 -0700, mdipierro napísal(a):

web2py.app.test.w2p

mdipierro

unread,
Aug 7, 2010, 7:29:58 PM8/7/10
to web2py-users
I am using trunk version
Version 1.82.1 (2010-08-04 18:57:33)
and the code you sent me works perfectly.

Either I do not understand the problem or this is a browser issue.
What os and browser do you use?

Massimo
>  web2py.app.test.w2p
> 100KViewDownload

Julius Minka

unread,
Aug 9, 2010, 4:27:19 AM8/9/10
to web...@googlegroups.com
Yes, now I see. It is browser issue.
I am on Ubuntu Linux 10.04.

It works on Firefox, Chromium, Konqueror.
it doesn't on Opera 10.60 and Epiphany, Midori (both are based on WebKit
rendering engine)

Hope this helps.
Julius

V Sobota, 7. august 2010 o 16:29 -0700, mdipierro napísal(a):

mdipierro

unread,
Aug 9, 2010, 4:28:59 AM8/9/10
to web2py-users
If you ding out what the problem is perhaps we can improve the code
and make it more cross-browser compatible.

Julius Minka

unread,
Aug 9, 2010, 4:48:28 AM8/9/10
to web...@googlegroups.com
I am not able to fix this, but I am willing to test it again if needed.
Julius

V Pondelok, 9. august 2010 o 01:28 -0700, mdipierro napísal(a):

mdipierro

unread,
Aug 9, 2010, 5:23:18 AM8/9/10
to web2py-users
Does any of the browsers with problem have a debug feature that allow
you to see if there is JS error?

Julius Minka

unread,
Aug 9, 2010, 7:20:54 AM8/9/10
to web...@googlegroups.com
I didn't get any JS error.

Details:
Epiphany has Webinspector which allowed me to run JS with debugging
enabled. It didn't throw any error while doing that.

Opera has its Dragonfly which does similar things. Neither it reported
any error.


Just to note:
Opera behaves differently from Epiphany. In Epiphany, the form
disappears after submission, in Opera nothing happens, screen remains as
it was in beginning.

Julius

V Pondelok, 9. august 2010 o 02:23 -0700, mdipierro napísal(a):

Julius Minka

unread,
Aug 10, 2010, 4:07:31 AM8/10/10
to web...@googlegroups.com
Massimo,

I got a message from a friend telling me the form isn't displayed in IE8
at all.
It is from my application available at http://93.184.68.161:9999/real

If you would like to see the response from the search you need to choose
Predaj
Prievidza
2-izbovy byt


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; .NET4.0C; .NET4.0E)
Timestamp: Tue, 10 Aug 2010 07:05:34 UTC

Message: Invalid argument.
Line: 116
Char: 165
Code: 0
URI: http://93.184.68.161:9999/real/static/jquery.js

Did you see the form working in an IE? Which version?
Julius


V Pondelok, 9. august 2010 o 13:20 +0200, Julius Minka napísal(a):

Julius Minka

unread,
Aug 10, 2010, 7:07:30 AM8/10/10
to web...@googlegroups.com
Form not displaying in IE was caused by other Jquery stuff on the page.
Sorry for bothering you.
However, redirection doesn't work in IE6.
Julius


V Utorok, 10. august 2010 o 10:07 +0200, Julius Minka napísal(a):

Reply all
Reply to author
Forward
0 new messages