The root_factory function you pass to the configurator should be a function
that takes the request as a parameter right? So if you keep it as an
attribute on the root resource and can be accessed from any resource that
is location aware. like ....
class Root(object):
def __init__(self, request):
self._request = request
from pyramid.traversal import find_root
find_root(self)._request
http://docs.pylonsproject.org/projects/pyramid/en/latest/api/traversal.html?highlight=traversal#pyramid.traversal.find_root
so the view passing the request to the model seems redundant to me.
Thomas G. Willis
On Fri, Jun 7, 2013 at 12:51 PM, Wade Leftwich <[email protected]> wrote:
> Hi,
>
> I'm putting together a little demo using Pyramid with a MongoDB back end
> and routes-type url dispatch.
>
> The pyramid_mongodb scaffold and all the example code I've seen attach the
> Mongo connection to each request, and the view_callable in turn passes it
> to the model. However, the SQLAlchemy scaffold uses a module-level Session
> object which gets an engine bound to it at startup, so functions that query
> the db do not need to receive a db connection explicitly. So, which is the
> more Pyramidal way to do it?
>
> That's assuming that a module level Mongo connection will work
> satisfactorily. According to the discussion at
> https://groups.google.com/forum/?fromgroups#!topic/pylons-discuss/6bLGOXngVvY
> it
> will, and my current toy implementation works that way; but I have seen
> some observations that it may cause problems with authenticated Mongo
> connections. I'll confess right now that my understanding of thread-local
> db connections is sketchy.
>
> I can see an explicit-vs-implicit argument in favor of associating a db
> connection with each request; vs a Law of Demeter argument in favor of
> keeping any knowledge of requests out of models, and knowledge of db
> sessions out of views.
>
> Any advice appreciated. And in case I am revisiting a long-settled
> discussion, apologies and thanks in advance for a link.
>
>
> Wade Leftwich
> Ithaca, NY
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.