5.2.6 draco.session -- the Session object

The Session object provides access to the builtin automated session management. Its global instance stored under the name session in the current module.

Session management is not always available. If a web robot is detected by Draco, no session is generated. This has the advantages that search engines will not index URLs that contain session ids and that no spurious sessions are being generated. So before using session management, you should check that it is available by checking the global session instance for non-zeroness.

The Session object also provides access to the session namespace using the namespace API. This means that you can get, set and remove session variables using Python's dictionary syntax on the Session object. A small example:

from draco.session import session

session['spam'] = 'spamspam
del session['spam']

class Session( )
Global Draco object that contains all functionality related to the builtin automated session management.

namespace( scope)
Return a session subnamespace with scope scope. Session namespaces with different scopes are independant. The default namespace (the one available from the global Session object) has the scope '__system__'.

sessionid( )
Return the session id of the current session. Session ids are strings that contain a random number and a checksum5.1 and are used to index all session data. If there is no session, None is returned.

login( userid)
Associate the integer userid with the current session. This makes the session a ``logged in'' session.

logout( )
Log out the current session. This resets the userid attribute set with login().

userid( )
Return the user id of the session if it session is logged in, or 0 if it is not.

persistent( )
Return nonzero if this is a persistent session or zero if it is not.

A persistent session is a session that is kept between browser sessions and has a greater expiration time5.2. Persistent sessions can be used to implement a ``remember me'' function. Only logged in session can be made persistent.

setPersistent( [persistent=1])
Make this session a persistent session if persistent is nonzero, or a volatile session if it is zero.



Footnotes

... checksum5.1
Currently, Draco uses 56 random bits plus a checksum which results in a 21 character session id.
... time5.2
By default 100 days but this can be changed in the config file. Non-persistent sessions have a default expiration time of 2 hours.