[albatross-users] Exception: set_page() passing wrong number of parameters to page_enter()?

Matt Goodall matt at pollenation.net
Wed May 21 05:24:17 EST 2003


On Tue, 2003-05-20 at 11:25, Dave Cole wrote:
> >>>>> "Sheila" == Sheila King <sheila at thinkspot.net> writes:
> 
> Sheila> I understand what you are saying here...except that it seems
> Sheila> to me that there is an exception. When someone submits a form,
> Sheila> and makes a cgi request to my application, then as part of the
> Sheila> cgi process, I get to determine the output to the browser. I
> Sheila> may well choose to have a particular page of my application be
> Sheila> the output of the cgi process. In that case, set_page seems to
> Sheila> make plenty of sense to me?
> 
> I see where you are coming from.  The problem is that the set_page()
> pretends that the server is in control of the transition from one page
> to another.
> 
> What might make more sense is to do something like this in every page
> module.  Place all of the application logic in the display function.
> Let a common module check the state of the session and have it force
> global behaviour if necessary.
> 
> Something as simple as this should do the trick.
> 
>   import myapp
> 
>   def page_display(ctx):
>       if myapp.check_session(ctx):
>           ctx.run_template('this-page-template.html')
> 
> Then in the myapp module you just need to something like.
> 
>   def check_session(ctx):
>       if ctx.locals._user:
>           return 1
>       if ctx.req_equals('login'):
>           if user_is_valid(ctx.locals.user, ctx.locals.passwd):
>               ctx.locals._user = ctx.locals.user
>               ctx.add_session_vars('_user')
>               return 1
>       ctx.run_template('login.html')
>       return 0
> 
> Sheila> Although I'm certainly willing to go along with, and
> Sheila> understand that, this simply isn't the way the Random page
> Sheila> modules work. However, I'm having problems with almost any
> Sheila> method I try. Please see my other post to this list tonight,
> Sheila> on how the ctx.redirect('name') isn't working so hot for
> Sheila> me. Or maybe I'm just confused.
> 
> It is certainly easy to get confused with this stuff.
> 
> Sheila> I thought I understood that page_display() was what got called
> Sheila> when a page was simply requested in the URL, and
> Sheila> page_process() was used when a cgi form was submitted. But it
> Sheila> doesn't seem to be working that way for me.
> 
> It is really up to you where you place your code.  They page_enter(),
> page_process(), and page_display() are just convenient hooks in the
> Application.run() processing sequence.

As a general rule you can probably ignore page_enter() for random apps.

As Dave already mentioned in this thread, page_enter() is called
immediately after the page module is loaded. Something that is not clear
(without looking through the code) is that page_enter() is called
**before** the request is merged into the context, i.e. none of the
request parameters are available in the ctx.locals yet. That makes it
pretty useless for typical page processing.

> 
>     ctx = self.create_context()
>     ctx.set_request(req)
>     self.load_session(ctx)
>     self.load_page(ctx)                 # calls page_enter()
>     if self.validate_request(ctx):
>         self.merge_request(ctx)
>         self.process_request(ctx)       # calls page_process()
>     self.display_response(ctx)          # calls page_display()
>     self.save_session(ctx)
> 
> The sequence is described here:
> 
>         http://www.object-craft.com.au/projects/albatross/albatross/fig-presimpexec.html
> 
> - Dave




More information about the Albatross-users mailing list