[albatross-users] A minor nit on redirects...

Gregory Bond gnb at itga.com.au
Tue Nov 12 15:17:52 EST 2002


We have a "start over" link on the bottom of each page, which is supposed to
drop the whole session and start again. I implemented this as a link with 
href="prog.py?top=1", but selecting this left the "?top=1" in the address bar 
of the browser, even after moving several pages past the top.

So I thought, "Aha!  Use redirects!"

	class Top:
	    name = 'top'
	    def page_enter(self, ctx):
		if ctx.req_equals('top'):
		    ctx.remove_session()
		    ctx.redirect('')		# Start from the bare base URL

This _almost_ works.  It now leaves the url reading "<blah>/prog.py/" (i.e.
with a bogus trailing slash).  Various other things I tried left stuff like 
"<blah>/prog.py/prog.py/prog.py/"!  I know it's minor, but.... 

BTW: A hint - decide before you start coding whether you are going to use
server sessions or client sessions - the nav logic changes substantially
between the two!  Server sessions are much more flexible (e.g. you can also
navigate with HREFs, not just FORMs) but you need to be much more picky about
refresh/reload, and users abandoning sessions half way through and going back
to the top url, and such like.

Is there some way of saying "if there is no form data or URL args, then just 
ditch the session and start over"?  I've had to do something like this:

    def page_process(self, ctx):
	if ctx.req_equals('top') or len(ctx.request.field_names()) == 0:
	    ctx.set_page('top')

in the page_process of every page class.  The first clause is for the "start 
again" link, the second is for the case where the user abandons a session 
and navigates (or bookmarks) back to the top.

Greg.





More information about the Albatross-users mailing list