[albatross-users] User input sought

Andrew McNamara andrewm at object-craft.com.au
Fri Dec 6 13:08:32 EST 2002


>> Another possible option is to have add_session_vars raise an exception if
>> the variable doesn't already exist
>
>The problem I've run into a few times is having multiple paths into the 
>current page, some of which set 'blah' into the session (with an appropriate 
>value), some of which don't.  
>
>So I do something like:
>	ctx.add_session_vars('blah')
>	try:
>	    ctx.locals.blah
>	except AttributeError:
>	    ctx.locals.blah = 1
>which is ugly and long_winded.

Yep - Dave and I have been considering this - I also find myself doing
something like the above all the time. I guess a setdefault() method
for ctx.locals has the virtue of mirroring the setdefault() method
for mapping types. I'm not sure I like the idea of poluting the locals
namespace, however.

I guess my perfered option is a default_session_vars() method that both
registers and, if not already set, sets session vars. Should it set one
variable at a time, or should it take tuples as args? I think I'd prefer
the former - less chance of mistakes.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list