Get username and state from CherryPy request
[invirt/packages/invirt-web.git] / code / view.py
index 38569ed..1a63eda 100644 (file)
@@ -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')]}