Hash: SHA1

Iain Duncan wrote:
> Hey folks, I have some stuff in middleware that I need my models in a
> bfg traversal graph to be able to get at. But I'm not sure what the
> correct way for those to get at the environ is. I could tack the environ
> onto all objects starting at default_get_root but that seems kind of
> clunky. I was alternately thinking that I would make a factory that
> could be looked up via ZCML to get the item I want, but I'm not sure
> whether it's possible to get at the current request from a zca utility
> or adaptor. Is there someway to do something like
> ( abstract model is in middleware )
> <utility for="IAbstractModel" factory="dram.get_abstract_model"/>
> and have get_abstract_model in turn look up the wsgi environ by asking
> to get the current request from the IRequest interface? Or some other
> way to get at the request on the model side of traversal? Or is this
> considered bad form?

I would probably modifiy the root factory for your app to extract the
bits you need from middleware (via the WSGI environ) and hold them as
non-persistent attributes of the root object.  You could then use the
'find_root' API in the app whenever you needed to use those attributes.

- --
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

Repoze-dev mailing list

Reply via email to