HappySession is an easy-to-use session management product. It uses a cookie to store the session id (128-alphanumeric key) and the actual session data is stored in RAM. You specify a maximum session idle time, and expired session data are automatically deleted. HappySession is Zope-transaction-aware.
You can provide a comment/feedback through e-mail to me by using Feedback to this page's author
Version 0.1.1 fixes a problem on Linux platform where the session cookie is not erased properly when a session expires.
Download HappySession.tgz and untar it in your root Zope directory. Restart Zope.
Create a HappySession instance. It will be named SESSION.
The HappySession object behaves like a Python dictionary with extra bonus. If an item does not exist, it will safely return a .None value. Similarly, if an item is set to .None, it will automatically be deleted. You can store any kind of Python object inside HappySession, not just strings or numbers.
To set a session variable:
<dtml-call "SESSION.set(my_key,my_value)">
my_key
my_value
To view a session variable:
<dtml-var "SESSION['my_key']">
To view the session contents:
<dtml-var "_.str(SESSION)">
To iterate over all session keys:
<dtml-in "SESSION.keys()"> ... </dtml-in>
To clear session data:
<dtml-call "SESSION.clear()">
You can catch the Session-Not-Found exception by modifying your standard_error_message (usually located at the root of the Zope hierarchy tree) to something like:
<!--#var standard_html_header--> <!--#if error_message--> <!--#var error_message--> <!--#else--> <dtml-if "error_type == 'SessionNotFoundError'"> <dtml-return session_not_found_html> </dtml-if> .....
<!--#if error_message--> <!--#var error_message--> <!--#else-->
<dtml-if "error_type == 'SessionNotFoundError'"> <dtml-return session_not_found_html> </dtml-if>
.....
and then design and display your own session_not_found_html page.
After the Session-Not-Found exception is raised, the session cookie is set to an empty string, and the next time any SESSION method is called, a new session will start automatically.