Dominique.Holzwarth at ch.delarue.com
Dominique.Holzwarth at ch.delarue.com
Thu Mar 27 06:02:44 EDT 2008
Yes, there is _no_ 'req.session.save()' inside the 'if' (but inside the 'else') because I don't really want that 'if' to be executed anyway! When 'sessiontest2.py' is called (by hitting the form button) there already should be a valid session, which was created inside 'sessiontest1.py'. That's actually what I wanted to try out: One script (sessiontest1.py here) creates a session, then calls some functions from other scripts (myClass.show() from sessiontest2.py here) and eventually there's a request for the index() function of those other scripts (sessiontest2.py here). And those scripts should still know that existing session which was created by the very first script... :-) So again, when the index() from sessiontest2.py is called the session _should not_ be new. If it is, then there's something wrong, thus I don't even save that session... :-) Dominique -----Original Message----- From: Graham Dumpleton [mailto:graham.dumpleton at gmail.com] Sent: Donnerstag, 27. März 2008 10:31 To: Holzwarth, Dominique (Berne Bauhaus) Cc: mod_python at modpython.org Subject: Re: [mod_python] Another sessions problem... See comment below in source code. On 27/03/2008, Dominique.Holzwarth at ch.delarue.com <Dominique.Holzwarth at ch.delarue.com> wrote: > Hello everyone > > I've already did some testing with mod_python's session mechanism and so far it seemed to work nice. My latest test case doesn't work at all tho... > > I have to scripts, sessiontest1.py and sessiontest2.py, both are > directly in my "python-root" (the folder the publisher handler is > using) > > Sessiontest1.py: > ************************************************** > from mod_python import Session > import sessiontest2 > > secretText = "mysecret" > > def index(req): > myClassObject = sessiontest2.myClass() > msg = myClassObject.add() > req.session = Session.FileSession(req) > req.session['test'] = 5 > req.session['meinKlassenObjekt'] = myClassObject > req.session.save() > return myClassObject.show(req.session.id()) > > ************************************************** > > Sessiontest2.py > ************************************************** > from mod_python import Session > > secretText = "mysecret" > > def index(req): > req.session = Session.FileSession(req) > if req.session.is_new(): > return "Session is new: "+req.session.id() Isn't there a req.session.save() missing in this part of if statement before returning? Graham > else: > lala = req.session['test'] > myClassObject = req.session['meinKlassenObjekt'] > newVal = req.form.getfirst('button') > cnt = myClassObject.add(newVal) > req.session['meinKlassenObjekt'] = myClassObject > req.session.save() > return cnt > return "default return" > > class myClass: > def __init__(self): > self.counter = 0 > > def add(self, val=1): > self.counter = self.counter + val > return self.counter > > def show(self, *value): > msg = """ > <html><body> > <form action='/python/sessiontest2.py' method='post'> > <input name='counter' type='text' readonly value='%s'/> > <input name='new' type='text' /> > <input name='button' type='submit' value='Add' /> </form> > <p>ID: %s</p> > </body></html> > """ % (self.counter, value) > return msg > **************************************************** > > Here's what's happening: > > I call the sessiontest1.py which creates a new session (for a fresh browser window), does some stuff with the class-object, saves the object (resp. the session) and then it returns the html site generated from that class. > When I submit that form the sessiontest2.py script is called and in my opinion it should load the previously created session (and do the stuff inside the 'else'). However, it always creates a new session instead of using the old one... > > Maybe anyone got an idea what could be wrong? Would be really nice! > > Greetings > Dominique > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python >
|