Re: Using session2 in Quixote 2.5
"Mike Orr" <[email protected]> Fri, 28 Nov 2008 18:04:48 -0800
| Newsgroups | gmane.comp.web.quixote.user |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Nov 28, 2008 at 4:41 PM, Ed Prue <[email protected]> wrote: > 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 In my application I have a session module: === from session2.Session import Session as _Session class Session(_Session, object): def __init__(self, id): super(Session, self).__init__(id) self.message = None self.my_chemicals = [] self.my_message = None self.my_removed = [] self.search = None def __str__(self): return "<Session %s>" % pprint.pformat(vars(self)) def has_info(self): return True === In my top-level executable I have: === def session_manager(): """For developers' workstations.""" store = DirectorySessionStore(config.sessions_dir, create=True) return SessionManager(store, Session) def create_publisher(): quixote.DEFAULT_CHARSET = config.output_encoding publisher = Publisher(RootDirectory(), display_exceptions=config.display_exceptions, session_cookie_name="MyApp_Session", session_manager=session_manager(), ) return publisher === The attributes in the session object are, of course, specific to my application. -- Mike Orr <[email protected]>