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

Michael C. Neel neel at mediapulse.com
Thu Apr 24 07:05:34 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')

hth,
Mike

-----Original Message-----
From: VanL [mailto:vlindberg at verio.net] 
Sent: Wednesday, April 23, 2003 4:34 PM
To: Michael C. Neel
Cc: albatross-users at object-craft.com.au
Subject: Re: [albatross-users] Getting things *out* of session_vars?


Here is a pretty minimal example that shows the page_enter problem.

login.py: ================================

def page_enter(ctx):
    if not hasattr(ctx.locals, 'login_message'):
        setattr(ctx.locals, 'login_message',  'Please enter your 
username and password:')
    if not hasattr(ctx.locals, 'user'):
        setattr(ctx.locals, 'user', '')

def page_process(ctx):
    if ctx.req_equals('login'):
        if hasattr(ctx.locals, 'user') and hasattr(ctx.locals,
'passwd'):
            user, passwd = ctx.get_value('user'),
ctx.get_value('passwd')
            if user and passwd:
                if authenticate(user, passwd):
                    ctx.add_session_vars('user', 'passwd')
                    ctx.set_page('controlpanel')

    return

def page_display(ctx):
    ctx.run_template('login.html')
==========================================
login.html: ===================================

<html><head></head><body>
<al-form method="post">
<h1><al-value expr="login_message"></h1>
<al-input type="text" name="user" expr="user">
<al-input type="text" name="passwd">
</al-form>
</body></html>

==========================================

Run this and it shows up fine the first time.  If you submit true values

for user and passwd, it will forward just fine.  However, if you submit 
bad values:

Template traceback (most recent call last):
  File "/www/htdocs/albatross/new_cust_wizard/login.html", line 16, in
al-form <al-form method="post">
  File "/www/htdocs/albatross/new_cust_wizard/login.html", line 21, in
al-value

Traceback (most recent call last):
[Snip]
File "<albatross>", line 0, in ?
NameError: name 'login_message' is not defined


I thought that once I had defined a default value in page_enter, it 
would stay set. That is why I thought that perhaps page_enter was not 
being called.  Could someone point out my error?

Thanks,

VanL






More information about the Albatross-users mailing list