[albatross-users] Random pages and application model
Dave Cole
djc at object-craft.com.au
Fri Feb 21 15:39:01 EST 2003
> 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)
Doesn't that work?
> page2.py
> --------
>
> def page_enter(ctx):
> ctx.locals.obj = get_obj_from_somewhere(ctx.locals.objid)
Ahhh...
In a random application the page_enter() function gets called every
request. You could just take the page_enter() code and prepend it to
the page_process() function.
> 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().
That is a bit of a bugger. One thing you could do is subclass the
application and replace the run() method with a slightly re-ordered
sequence.
class MyApp(RandomModularSessionApp):
def run(self, req):
# My own processing sequence copied from
# RandomModularApp.run() but slightly resequenced.
> 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.
See if overriding the application run method gives you what you need.
The primary design goal of Albatross was to provide a toolkit from
which you can build your own application models. We provide some
examples pre-rolled which just happen to be useful for certain classes
of application.
I am more than a little interested to see if replacing
Application.run() is useful to you. Does it make your brain hurt, or
is it something useful?
- Dave
--
http://www.object-craft.com.au
More information about the Albatross-users
mailing list