Using zope adapter registry in Kotti

38 views
Skip to first unread message

Toni Haka-Risku

unread,
May 1, 2013, 4:32:22 PM5/1/13
to ko...@googlegroups.com
Hi,
I want to use zope adapters with kotti just like in Plone, but it seems when I try to register an adapter it's reseted when starting Kotti app. So there is no adapter to lookup when trying to access zca global registry.
Here is the code example::

ISomeContent(Interface):
    """  """

ICommentable(Interface):
    """ """

CommentableSomeContent(object):
    implements(ICommentable)
    __used__for = ISomeContent

    def foo(self):
        return "bar"


And here is the adapter registration:

from zope.interface.adapter import AdapterRegistry                        
registry = AdapterRegistry()                                              
registry.register([ISomeContent], ICommentable, '', CommentableSomeContent)  

When I try to registry.lookup1(...) during request the registry is empty. When/why does it reset? Is there a way to use ZCA adapters or similar?




Daniel Nouri

unread,
May 3, 2013, 2:30:32 PM5/3/13
to ko...@googlegroups.com, Toni Haka-Risku
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Using the ZCA within Pyramid is a bit special. See
http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/narr/zca.html

The short story is that Pyramid has per-app registries and that global
ZCA calls are somewhat incompatible. However, Kotti itself calls
`config.hook_zca()` (which is described in the link above). It is
*after* that call that you should be able to use the ZCA global API,
i.e. your code, just fine.

Concretely, try moving your adapter registration into the `includeme`
function. So that your code is executed after Kotti's call to
`config.hook_zca()`.

You may also want to consider "Disusing the Global ZCA API" as
described in the link above.


Daniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlGEAkgACgkQi2kx5isbD8zV+gCfQiAE2Ezd0Ta8y9Fa/zTc0zKR
npYAn0hIREvNwsfTemlsgjfGromLXYGc
=KfC3
-----END PGP SIGNATURE-----

Toni Haka-Risku

unread,
May 4, 2013, 4:20:57 AM5/4/13
to ko...@googlegroups.com, Toni Haka-Risku
I've put the registration code inside includeme but still it doesnt work. Are you sure? I can find the adapter right after the code, so it's registered correctly, but after another request the registry is again empy. If there is no solution, I would appreciate if you give a little example how to register adapter (and use it) using the pyramid registry from request.registry (or config.registry). It seems it's not working the same way like I've used to in Zope registry calls. 

- Toni

Daniel Nouri

unread,
May 4, 2013, 4:32:29 AM5/4/13
to ko...@googlegroups.com, Toni Haka-Risku
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/04/2013 10:20 AM, Toni Haka-Risku wrote:
> I've put the registration code inside includeme but still it
> doesnt work. Are you sure?

I am sure that you can use global ZCA calls after you called
`config.hook_zca()`, yes. I'm not sure why it's failing in your case.

> I can find the adapter right after the code, so it's registered
> correctly, but after another request the registry is again empy.
> If there is no solution, I would appreciate if you give a little
> example how to register adapter (and use it) using the pyramid
> registry from request.registry (or config.registry). It seems it's
> not working the same way like I've used to in Zope registry calls.

Tried `config.registry.registerAdapter` and
`config.registry.queryAdapter`? These should work just like their
equivalents in zope.component.


Daniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlGEx50ACgkQi2kx5isbD8wfagCfbIkSlGkO8ZDjg4ntd5hAQ/Ct
Ed8AnjX918kYfEVHDlnltW63dPhQKMAV
=If4s
-----END PGP SIGNATURE-----

Toni Haka-Risku

unread,
May 5, 2013, 10:12:15 AM5/5/13
to ko...@googlegroups.com, Toni Haka-Risku
Dunno why the config.hook_zca() isn't working for me but when using config.registry.registerAdapter and queryAdapter it's working fine. So I think this case is solved, thanks for your help!
Reply all
Reply to author
Forward
0 new messages