grokcore.component registring Components

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

grokcore.component registring Components

Christian Klinger
Hi,

together with Souheil we tried to use z3c.baseregistry[1] together with
GROK. Out of the box it does not work, because grokcore.component uses
some functions (provideUtility, provideAdatper, ...) from
zope.component. Souheil discoverd that this function use *always* the
globalSiteManager, which makes problems together with z3c.baseregistry.

We created a simple function (my_provideUtility) which works, Is it
possible to integrate this in grokcore.component? Are there any risks?

Thanks for your Help
Christian

[1] http://pypi.python.org/pypi/z3c.baseregistry

----------------%<------------------------------------------------------

def my_provideUtility(component, provides=None, name=u''):
     site = zope.component.hooks.getSite()
     if site is None:
         sm = zope.component.getSiteManager()
     else:
         sm = site.getSiteManager()
     sm.registerUtility(component, provides, name, event=False)


class GlobalUtilityGrokker(martian.ClassGrokker):
     ...

     def execute(self, factory, config, direct, provides, name, **kw):
         if not direct:
             factory = factory()
         config.action(
             discriminator=('utility', provides, name),
             callable=my_provideUtility,
             args=(factory, provides, name),
             )
         return True

----------------------->%---------------------------------------------------

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|

Re: grokcore.component registring Components

Christian Klinger
Hi,

sorry one mistake...

   if site is None:
       sm = zope.component.getGlobalSiteManager()

- Christian


> Hi,
>
> together with Souheil we tried to use z3c.baseregistry[1] together with
> GROK. Out of the box it does not work, because grokcore.component uses
> some functions (provideUtility, provideAdatper, ...) from
> zope.component. Souheil discoverd that this function use *always* the
> globalSiteManager, which makes problems together with z3c.baseregistry.
>
> We created a simple function (my_provideUtility) which works, Is it
> possible to integrate this in grokcore.component? Are there any risks?
>
> Thanks for your Help
> Christian
>
> [1] http://pypi.python.org/pypi/z3c.baseregistry
>
> ----------------%<------------------------------------------------------
>
> def my_provideUtility(component, provides=None, name=u''):
> site = zope.component.hooks.getSite()
> if site is None:
> sm = zope.component.getSiteManager()
> else:
> sm = site.getSiteManager()
> sm.registerUtility(component, provides, name, event=False)
>
>
> class GlobalUtilityGrokker(martian.ClassGrokker):
> ...
>
> def execute(self, factory, config, direct, provides, name, **kw):
> if not direct:
> factory = factory()
> config.action(
> discriminator=('utility', provides, name),
> callable=my_provideUtility,
> args=(factory, provides, name),
> )
> return True
>
> ----------------------->%---------------------------------------------------
>


_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|

Re: grokcore.component registring Components

Sylvain Viollon
In reply to this post by Christian Klinger

Op 29 nov 2011, om 13:40 heeft Christian Klinger het volgende geschreven:

> Hi,
>

   Hello,

> together with Souheil we tried to use z3c.baseregistry[1] together with GROK. Out of the box it does not work, because grokcore.component uses
> some functions (provideUtility, provideAdatper, ...) from zope.component. Souheil discoverd that this function use *always* the globalSiteManager, which makes problems together with z3c.baseregistry.
>
> We created a simple function (my_provideUtility) which works, Is it possible to integrate this in grokcore.component? Are there any risks?


   I think we can update grokcore.component so it can work like you say. We should have a file that rebuild those provide functions (for all the things) and use them. Of course them should not be called my_something. I hate stuff that starts with my_.

  +42

  Sylvain,

--
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands



_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev