On Mon, 14 Jul 2008 16:09:18 -0400 Etienne Robillard <[EMAIL PROTECTED]> wrote:
> > > Hi all, > > I'd like to have your input and comments on using decorators > functions for adding extra options to the request.environ object. > > For instance, here's a decorator whichs adds a "scoped" session > object into request.environ: > > def with_session(engine=None): > """ > Decorator function for attaching a `Session` instance > as a keyword argument in `request.environ`. > """ > def decorator(view_func): > def _wrapper(request, *args, **kwargs): > scoped_session.set_session(engine) > request.environ['_scoped_session'] = getattr(scoped_session, > 'sessio > return view_func(request, *args, **kwargs) > return wraps(view_func)(_wrapper) > return decorator > > Then it can be used as follows: > > @with_session(engine=engine): > def view_blog_list(request, *args, **kwargs): > # get the local session object for this > # request (thread-local) > sess = request.environ['_scoped_session'] > # do stuff with the Session object here... > ... > > Is this a good approach, or can this be adapted to work > in multithreaded environments ? > > For details, you can checkout the source code of notmm, which > holds the current implementation of the with_session decorator: > > $ hg clone -r tip http://gthc.org/projects/notmm/repo/ notmm > For more details about notmm, please see here: http://gthc.org/projects/notmm/ > > Thanks and Regards, > > Etienne Hi, I'm forwarding this on pylons-discuss. I'd be interested in feedback on how to integrate SQLAlchemy in Pylons. Can this decorator (with_session) works on/with Pylons controllers too ? Cheers! :) Etienne -- Etienne Robillard President and Sr. Developer, Green Tea Hackers Club Cell: 514-962-7703 | <http://gthc.org/> | <[EMAIL PROTECTED]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
