Differences between revisions 1 and 2
Revision 1 as of 2005-06-15 11:18:50
Size: 1628
Editor: ZoomQuiet
Comment:
Revision 2 as of 2009-12-25 07:11:10
Size: 1630
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 23: Line 23:
 * `Session` contains information about the session. Most of its attributes are of little interest to a web application programmer; the single exception is the `.user` attribute, which you can use to record user information. The data type for `.user` isn't defined, so you can set it to a string, an instance of your own User class, or whatever you wish. The [http://www.mems-exchange.org/software/dulcinea/ Dulcinea package] includes a `User` class that you may want to look at.  * `Session` contains information about the session. Most of its attributes are of little interest to a web application programmer; the single exception is the `.user` attribute, which you can use to record user information. The data type for `.user` isn't defined, so you can set it to a string, an instance of your own User class, or whatever you wish. The [[http://www.mems-exchange.org/software/dulcinea/|Dulcinea package]] includes a `User` class that you may want to look at.

Problem

You wish to store server-side information about client agents; this information should follow around users as they browse through the application.

Solution

Enable sessions by using the SessionPublisher class instead of the regular Publisher. In your top-level script, simply do:

from quixote.publish import SessionPublisher
...
publisher = SessionPublisher()

Discussion

SessionPublisher uses two auxiliary classes:

  • SessionManager is a singleton (meaning there's only one instance of it) that's responsible for creating new Sessions and storing them.

  • Session contains information about the session. Most of its attributes are of little interest to a web application programmer; the single exception is the .user attribute, which you can use to record user information. The data type for .user isn't defined, so you can set it to a string, an instance of your own User class, or whatever you wish. The Dulcinea package includes a User class that you may want to look at.

The standard version of SessionManager stores sessions in a Python dictionary. This means that you must be invoking Quixote through some mechanism that uses long-lived processes; this rules out CGI, but any of FastCGI/SCGI/mod_python will work fine. If you have multiple processes, though, sessions will not be shared between them. For such situations you would have to write a SessionManager subclass that stored sessions in a relational database or disk file.


CategoryCookbook

QuixoteCookbook/UsingSessions (last edited 2009-12-25 07:11:10 by localhost)