Differences between revisions 3 and 4
Revision 3 as of 2009-07-09 14:56:30
Size: 3270
Comment:
Revision 4 as of 2009-07-09 14:57:21
Size: 3254
Comment:
Deletions are marked like this. Additions are marked like this.
Line 81: Line 81:
=== 200907 ===

FAQ

Not directly via config, no.

Your post pointed me in the right direction. I tried your idea, but
the SessionMiddleware is needed (they call it core middleware  for a
reason). Other code expects it to be there, so it can't be just
removed. Instead, I went one level deeper and modified the
SessionMiddleware itself to NOT set a cookie. I didn't want to modify
the beaker package itself of course (bad practice). I could in theory
subclass the beaker SessionMiddleware and then sublass AppConfig to
add my custom SessionMiddleware, but it becomes a little cumbersome.
So, I ended up just replacing the __call__the method of the original
beaker SessionMiddleware in my AppCfg.py file. The commented lines
bellow are the lines that set the cookie:


### Start code #####
from beaker.middleware import SessionMiddleware
from beaker.session import SessionObject
def custom_session_middleware__call__(self, environ, start_response):
   session = SessionObject(environ, **self.options)
   if environ.get('paste.registry'):
       if environ['paste.registry'].reglist:
           environ['paste.registry'].register(self.session, session)
   environ[self.environ_key] = session
   environ['beaker.get_session'] = self._get_session

   def session_start_response(status, headers, exc_info = None):
       #if session.accessed():
       #    session.persist()
       #    if session.__dict__['_headers']['set_cookie']:
       #        cookie = session.__dict__['_headers']['cookie_out']
       #        if cookie:
       #            headers.append(('Set-cookie', cookie))
       return start_response(status, headers, exc_info)
   return self.wrap_app(environ, session_start_response)

SessionMiddleware.__call__ = custom_session_middleware__call__
### End code #####

mounting test-controllers/getting root-controller instance

Assuming the paster-stuff is bootstrapped through code like

  here_dir = os.path.dirname(os.path.abspath(ableton.__file__))
  conf_dir = os.path.dirname(here_dir)
  wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)

you then can do it simply like this (inside a function/method!!)

  import myproject.controllers.root as root
  root.RootController.mountpoint = TestController()

Then you can access the controller through the usual

  self.app.get("/mountpoint/action")

Of course mounting of whole controller hierarchies is perfectly fine.

So I create a function in our base-test-class that allows to register a passed
controller for a given mountpoint. Voila, greatness ensues.

Errors

Addition modules required

ImportError: No module named MySQLdb

Fixed with:

easy_install MySQL-python

ToscaWidget conflict

  Installed /home/lek/work/mine/tg2env/lib/python2.6/site-packages/tw.forms-0.9.7.2-py2.6.egg
  error: Installed distribution ToscaWidgets 0.9.7.1 conflicts with requirement ToscaWidgets>=0.9.7.2
  • Fixed with:

easy_install -U tw.forms

MyWiki: TurboGears2/faq (last edited 2011-02-02 19:40:03 by LukaszSzybalski)