[mod_python] Another sessions problem...

Graham Dumpleton graham.dumpleton at gmail.com
Thu Mar 27 05:30:35 EDT 2008


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
>


More information about the Mod_python mailing list