From bfdba2e4f73fced5d2d37b1351016168883e996b Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Sun, 9 Aug 2009 18:45:26 -0400 Subject: [PATCH] Get username and state from CherryPy request svn path=/package_branches/invirt-web/cherrypy-rebased/; revision=2669 --- code/main.fcgi | 3 ++- code/main.py | 4 ++-- code/view.py | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/code/main.fcgi b/code/main.fcgi index 6d5543e..03f899c 100755 --- a/code/main.fcgi +++ b/code/main.fcgi @@ -19,7 +19,8 @@ if __name__=="__main__": conf_file = os.path.join(base_dir, 'main.conf') app = cherrypy.tree.mount(InvirtWeb(), '/' if dev else '/main.fcgi', - {'/': {'tools.staticdir.root': static_dir}, + {'/': {'tools.staticdir.root': static_dir, + 'tools.invirtwebstate.on': True}, '/static': {'tools.staticdir.on': True, 'tools.staticdir.dir': static_dir} }) diff --git a/code/main.py b/code/main.py index c3db122..fd95e84 100755 --- a/code/main.py +++ b/code/main.py @@ -55,10 +55,10 @@ class InvirtWeb(View): @cherrypy.expose @cherrypy.tools.mako(filename="/list.mako") - def list(self, username): + def list(self): """Handler for list requests.""" checkpoint.checkpoint('Getting list dict') - d = getListDict(username, state) + d = getListDict(cherrypy.request.login, cherrypy.request.state) checkpoint.checkpoint('Got list dict') return d index=list diff --git a/code/view.py b/code/view.py index 38569ed..1a63eda 100644 --- a/code/view.py +++ b/code/view.py @@ -5,6 +5,8 @@ from mako.template import Template from mako.lookup import TemplateLookup import simplejson import datetime, decimal +from invirt.config import structs as config +from webcommon import State class MakoHandler(cherrypy.dispatch.LateParamPageHandler): """Callable which sets response.body.""" @@ -78,5 +80,11 @@ def require_login(): cherrypy.tools.require_login = cherrypy.Tool('on_start_resource', require_login) +def invirtwebstate_init(): + """Initialize the cherrypy.request.state object from Invirt""" + cherrypy.request.state = State(cherrypy.request.login) + +cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100) + class View(object): _cp_config = {'tools.mako.directories': [os.path.join(os.path.dirname(__file__),'templates')]} -- 1.7.9.5