On 10/14/2014 06:28 PM, Thierry Florac wrote:
Hi,For your information, this is the code I've produced to use local components registry: @subscriber(ContextFound) def onContextFound(event): context = event.request.context if ISite.providedBy(context): pyramid.threadlocal.manager.push({'registry': context.getSiteManager(), 'request': event.request}) So simple! After that, the only difference with common Zope3 code is when calling for a utility or adapter, because I have to use: util = get_current_registry().queryUtility(IUtility) I tried to use "zope.component.hooks.setSite()" function into subscriber code, but it doesn't seem to do anything in a Pyramid application... Any better idea?
TBH, I'd try to avoid doing this. There's no particular reason to replace Pyramid's registry as the result of an event. Pyramid's use of a ZCA registry is completely incidental to what you want to do, I think. Pretend it doesn't use one, instead, and create your own threadlocal stack (if required, might not be).
- C
Best regards, Thierry 2014-10-14 7:49 GMT+02:00 Wichert Akkerman <[email protected] <mailto:[email protected]>>: > On 14 Oct 2014, at 04:25, Tres Seaver <[email protected] <mailto:[email protected]>> wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 10/13/2014 09:54 PM, Chris Rossi wrote: >> My naive first take is just write a utility method: >> >> def find_sitemanager(context): """ Find nearest site manager, walking >> back up the tree from 'context'. """ >> >> Then, don't use the global API, but call getUtility and queryUtility >> on the local registry that you find with your utility method. > > (Totally untested) You could subscribe to the IContextFound event, and > set the sitemanager based on context from within it: the global APIs > would "Just Work" at that point. I bet you can also (and perhaps must?) update request.registry to the closest found registry at that point. Wichert. -- 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] <mailto:pylons-discuss%[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout. -- http://www.imagesdusport.com -- http://www.ztfy.org -- 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] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
-- 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. For more options, visit https://groups.google.com/d/optout.
