Here is the answer to smatyases' question:

http://www.mail-archive.com/[email protected]/msg02557.html

.. basically, you have to do some funky things to make your session
available via all your 'subapps'.

I added a sub-page to the cookbook with this 'solutions'.

http://webpy.org/cookbook/sessions_with_subapp

thanks!

On Aug 1, 6:55 am, Branko Vukelic <[email protected]> wrote:
> smatyas,
>
> Not that I don't understand your frustration, but sessions do work. At
> least they do for me, on my setup using DBStore. Meanwhile, how do you
> initialize the usersession object? Could you paste that part of the
> code?
>
>
>
> On Sat, 2009-08-01 at 03:51 -0700, smatyas wrote:
> > Can anyone help?!?
>
> > I can't seem to get web.session.Session(...) to operate properly when
> > using it for a practical user story. I've tried the example verbatim
> > and it works (yeah for the cookbook!):
> > {code}
> > import web
> > web.config.debug = False
> > urls = (
> >     "/count", "count",
> >     "/reset", "reset"
> > )
> > app = web.application(urls, locals())
> > session = web.session.Session(app, web.session.DiskStore('sessions'),
> > initializer={'count': 0})
>
> > class count:
> >     def GET(self):
> >         session.count += 1
> >         return str(session.count)
>
> > class reset:
> >     def GET(self):
> >         session.kill()
> >         return ""
>
> > if __name__ == "__main__":
> >     app.run()
>
> > {code}
>
> > NOW, the moment I try to actually use session for anything
> > *substantia*, I get an error when I try to access the session. Notice
> > the body of storeInSession() and the
>
> > {code}
> > import web
> > from web import form
> > from run import render, usersession
> > from com.fiveamsolutions.lchange.Config import Config
> > ...
> > class Base:
> >     cfg = Config(None)
> > ...
> > class login(Base):
> >     def renderLogin(self, form):
> >         return render.login('', self.cfg.getversion(), None, form)
> >     def GET(self):
> >         form = loginform()
> >         return self.renderLogin(form)
> >     def POST(self):
> >         form = loginform()
> >         if not form.validates():
> >             return self.renderLogin(form)
> >         else:
> >             print "Grrreat success! username: %s, password: %s,
> > usertree: %s" % (form.d.username, form['password'].value,
> > form.d.usertree)
> >             d = DataService()
> >             validuser = d.login_bind(form.d.username, form.d.password,
> > form.d.usertree)
> >             if not validuser:
> >                 print "LOGIN FAILED -- return to login page with error
> > message"
> >                 form.note = "Invalid username and/or password, please
> > try again."
> >                 return self.renderLogin(form)
> >             print "LOGIN SUCCESSFULL"
> >             self.storeInSession(form.d.username, form.d.usertree)
> >     def storeInSession(self, username, usertree):
> >         usersession.loggedin = True
> >         usersession.username = username
> >         usersession.usertree = usertree
>
> > ...
> > class logout(Base):
> >     def GET(self):
> >         print "killing session for %s" % (usersession.username)
> >         usersession.kill()
> >         return render.logout('', self.cfg.getversion(), None)
> >     def POST(self):
> >         self.GET()
> > {code}
>
> > Below is the corresponding output:
>
> > {run}
> >http://0.0.0.0:1234/
> > Grrreat success! username: smatyas, password: asdf, usertree: People
> > LOGIN SUCCESSFULL
> > 127.0.0.1:57966 - - [01/Aug/2009 06:46:03] "HTTP/1.1 POST /login" -
> > 200 OK
> > Traceback (most recent call last):
> >   File "/Users/smatyas/PYTHONENV/WEBPY_31/lib/python2.5/site-packages/
> > web/application.py", line 242, in process
> >     return self.handle()
> >   File "/Users/smatyas/PYTHONENV/WEBPY_31/lib/python2.5/site-packages/
> > web/application.py", line 233, in handle
> >     return self._delegate(fn, self.fvars, args)
> >   File "/Users/smatyas/PYTHONENV/WEBPY_31/lib/python2.5/site-packages/
> > web/application.py", line 412, in _delegate
> >     return handle_class(cls)
> >   File "/Users/smatyas/PYTHONENV/WEBPY_31/lib/python2.5/site-packages/
> > web/application.py", line 387, in handle_class
> >     return tocall(*args)
> >   File "/Users/smatyas/dev/projects/ocio/CentralAuth/ChangePass/src/
> > public.py", line 182, in GET
> >     print "killing session for %s" % (usersession.username)
> >   File "/Users/smatyas/PYTHONENV/WEBPY_31/lib/python2.5/site-packages/
> > web/utils.py", line 923, in __getattr__
> >     return getattr(self._getd(), key)
> >   File "/Users/smatyas/PYTHONENV/WEBPY_31/lib/python2.5/site-packages/
> > web/utils.py", line 68, in __getattr__
> >     raise AttributeError, k
> > AttributeError: 'username'
>
> > 127.0.0.1:57969 - - [01/Aug/2009 06:46:16] "HTTP/1.1 GET /logout" -
> > 500 Internal Server Error
>
> > {run}
>
> > I'm both deeply sadden by this as a developer that is both new to
> > webpy and python (like 24 hours total programmer + reading), if
> > that..  I can't believe this framework just doesn't work.  I really
> > need to crank out this dinky web app with LDAP backend yet, I can't
> > seem to get webpy to work. Any suggestions? Should I drop webpy all
> > together and try something else? I've heard of Beaker (http://
> > beaker.groovie.org/) but am unsure how exactly to integrate this with
> > webpy, etc...
>
> > Can anyone help?!?
>
> --
> Branko
>
> eml: [email protected]
> alt: [email protected]
> blg:http://sudologic.blogspot.com/
> img:http://picasaweb.google.com/bg.branko
> twt:http://www.twitter.com/foxbunny/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to