durusmail: quixote-users: Using session2 in Quixote 2.5
Using session2 in Quixote 2.5
2008-11-29
2008-11-29
Using session2 in Quixote 2.5
Ed Prue
2008-11-29
Hello.  I'm a new Quixote user.  I found Quixote earlier this year,
and the design philosophy really appealed to me, so I chose it over
"djother-framework" that I was evaluating.

I'm trying to use session2, but the available documentation (I think
I've found all there is on the web -- Titus, Dave, mems-exchange,
Linux Journal overview, whatever else Google would yield) -- the
available documentation shows not-quite-enough to get me there.  I've
experimented some, but a definitive example would help.  There are
three things I'm reaching for:

1) What to use session2 for --
    Just as a cookie generator/retriever, with just enough user ID
info stored in it to allow me to retrieve a user profile from wherever
I store user profiles in my database?  This seems "correct" to me

    Alternately, I might stash more user configuration type info in
the session object -- but that seems "less correct" to me, for some
reason I can't yet rationalize (don't use cookies for general storage,
or some such...)


2) Which session2.Session() and session2.SessionManager() methods to
override -- it looks to me like Session.start_request() is the only
Session method I need to override; and maybe nothing in
SessionManager(?)


3) When to call what seem to me to be the key methods -- or if I
should call any methods myself(?) Perhaps, if I just override the
correct methods, I don't need to call anything(?)  Comments are not
particularly helpful here.  From SessionManager.get_session():

        "Note that this method does *not* cause the new session to be
        stored in the session manager, nor does it drop a session cookie
        on the user.  Those are both the responsibility of
        finish_successful_request()."

And then, from SessionManager.maintain_session():

        "This method is called after servicing an HTTP request, just
        before the response is returned.  If a session contains
        information, a cookie is dropped on the client and True
        is returned.  If not, the session is forcibly expired and
        False is returned."

Ahh! -- after looking again, I see that finish_successful_request()
calls maintain_session(), so I guess that answers that question --
finish_successful_request() will take care of storing the session
content to the designated store, as long as a session exists and
maintain_session() doesn't return a False value.

So -- it looks like, to make basic use of session2, I should just
subclass session2.Session, override Session.start_request(), choose a
session storage type, follow the available example code for creating a
store and a session manager, and viola! -- be on my way.  Has my
"read-the-source" discipline (which is not yet a repeatable discipline
for me :) led me to right use of session2?  I'd appreciate any
comments, corrections, elucidations, etc.

Thanks for the great documentation and examples that *are* available
on the web for getting and using Quixote.  It was (relatively)
painless to get up and running.  I'm in development now -- haven't yet
deployed my first production site (in a smallish medium-sized
corporation.)  I hope that the lack of traffic on the mailing list
means that folks are busy using Quixote, and not having many problems
:)

Cheers,
Ed Prue
Quixote user since 8/2008
reply