[albatross-users] Getting things *out* of session_vars?

Dave Cole djc at object-craft.com.au
Thu Apr 24 09:31:32 EST 2003


> ctx.add_session_vars('user', 'passwd') should be done in page_enter.
> And (someone correct me if I'm wrong) but in page_enter you can
> count on locals being empty.  So you can simply have:
> 
> def page_enter(ctx):
>     ctx.locals.login_message = 'Please enter your username and password:'
>     ctx.locals.user = ''
>     ctx.locals.passwd = ''
>     ctx.add_session_vars('user', 'passwd', 'login_message')

That should certainly do it.

The way to answer whether or not to place something in the session is
to decide if you want it to survive a round trip to and from the
browser.

If you want ctx.locals.login_message to be in ctx.locals when you
display the next page you either have to place it in the session, or
recreate it in your page_process() method/function.

The sequence of calls to your page_* code goes a bit like this:

    # session loaded before this point
    if this_is_a_new_session:
        ctx.set_page(first_page)
    page_process(ctx)
    page_display(ctx)
    # session saved after here

Calling ctx.set_page(name) loads the new page and then calls
page_enter().  This happens at the start of a new session, and when
code in page_process() changes page via ctx.set_page().

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list