[albatross-users] Random pages and application model
Matt Goodall
matt at pollenation.net
Fri Feb 21 12:43:29 EST 2003
Hi,
There's a nice description of how the application model relates to the
page_xxx() methods for 'stateful' applications in the mailing list
archive but I've not come across an equivalent explanation for 'random'
applications.
>From debug traces I see the following sequence whenever the page is
requested:
page_enter(ctx)
page_process(ctx)
page_display(ctx)
I have no problems with page_process() and page_display() but I don't
quite understand what use page_enter() has? It seems a bit redundant to
me since the request parameters are not merged into ctx.locals until
**after** page_enter() is called.
It's probably worth explaining that what I expected to be able to do is
something like this (not tested):
page1.py
--------
def page_process(ctx):
if ctx.req_equals('edit'):
ctx.redirect('page2?objid=%s' % ctx.locals.objid)
page2.py
--------
def page_enter(ctx):
ctx.locals.obj = get_obj_from_somewhere(ctx.locals.objid)
def page_process(ctx):
if ctx.req_equals('submit'):
# save data
ctx.redirect('page1')
elif ctx.req_equals('cancel'):
ctx.redirect('page1')
def page_display(ctx):
ctx.locals.attr1 = ctx.locals.obj.attr1
ctx.locals.attr2 = ctx.locals.obj.attr2
ctx.run_template('page2.html')
The problem is that, as mentioned above, the request parameter, objid,
is not available during page_enter(), it's only there for
page_process().
One workaround is to put the object loading code in an else block in
page_process which doesn't feel like the right place for it. The
alternative is to transfer objid using a session var but I prefer not to
use the session where possible - it's just something else that needs
managing.
Oh yeah, my app class extends RandomModularSessionApp and I'm running
the application in mod_python on Linux if that makes any difference.
Thanks for any help.
Cheers, Matt
--
Matt Goodall, Technical Director
Pollenation Internet Ltd, http://www.pollenation.net
e: matt at pollenation.net
t: 0113 2252500
More information about the Albatross-users
mailing list