ZCA objectEventNotify + Pyramid Subscribers

64 views
Skip to first unread message

Robin Harms Oredsson

unread,
Jun 10, 2011, 8:09:24 AM6/10/11
to pylons-discuss
Hi all,

I'm having some trouble with regular Zope events in Pyramid. We've
used repoze.folder which basically fires off regular objectEventNotify
when something happends. As far as i can see, the pyramid subscriber
doesn't catch them.

Here's an example:

from repoze.folder.interfaces import IObjectAddedEvent
from pyramid.events import subscriber

@subscriber(IObjectAddedEvent)
def do_stuff(event):
...

When i add something to a repoze folder, it uses Zopes
objectEventNotify to add the new event. That isn't caught. If i use
the registered notify method on registry it works as expected. Is this
by design or am I doing something wrong here?

I'd really appreciate some hints in the right direction.

Cheers,
Robin

Danny Navarro

unread,
Jun 10, 2011, 9:07:04 AM6/10/11
to pylons-...@googlegroups.com
Hi Robin,

repoze.folder uses zope.component to send events. Don't take my word
but I think that in order to catch those events you would need to set
your pyramid application to use zope.component.
http://docs.pylonsproject.org/projects/pyramid/1.0/narr/zca.html#enabling-the-zca-global-api-by-using-the-zca-global-registry

Alternatively you could create your own event and send it explicitly
whenever you add something to the folder. I don't know how to make
custom pyramid events, but it shouldn't be too difficult.

--
Danny Navarro | http://dannynavarro.net

> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>
>

Tim Hoffman

unread,
Jun 11, 2011, 8:50:14 PM6/11/11
to pylons-...@googlegroups.com
Hi

You will find that by default zope.event is using an alternate registry so the pyramid subscriber events won't match.
I am using objectEventNotify on appengine with pyramid, and as the post from Danny points out
you will need to ensure that zope.event and the pyramid registries are the same by using the zca global registry.

Rgds

Tim

Chris McDonough

unread,
Jun 11, 2011, 8:55:15 PM6/11/11
to pylons-...@googlegroups.com

config.hook_zca() works too without requiring using the global registry:

<http://docs.pylonsproject.org/projects/pyramid/1.0/narr/zca.html#enabling-the-zca-global-api-by-using-hook-zca>

- C

>
> Rgds
>
> Tim


>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/NSBSJ4ojZQ4J.


> To post to this group, send email to pylons-...@googlegroups.com.

> To unsubscribe from this group, send email to pylons-discuss
> +unsub...@googlegroups.com.

Danny Navarro

unread,
Jun 12, 2011, 9:21:36 AM6/12/11
to pylons-...@googlegroups.com
Hey,

I was curious about how to write custom events in Pyramid so I toyed
around a bit and came up with this blog post:
http://blog.dannynavarro.net/2011/06/12/using-custom-events-in-pyramid/

In the example I show the events work properly without hooking the ZCA.

--
Danny Navarro | http://dannynavarro.net

> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.

Robin Harms Oredsson

unread,
Jun 13, 2011, 3:36:01 AM6/13/11
to pylons-...@googlegroups.com
Hi all, and thanks for your replies. It's nice to know there's a lot
of dedicated uhm... "Pyramidos"(?) out there :)

I've read the documentation several times, but when you do something
with an external application it doesn't seem to behave the way you
would expect it. And it doesn't matter if you use the global or the
local registry. (It will always work when you use Pyramids registry,
so that's not the problem)

Check this out:

During configuration stage:
config = Configurator(settings=settings)
config.hook_zca()
config.include('pyramid_zcml')
config.load_zcml('voteit.core:configure.zcml') #contains workflow ZCML
stuff for repoze.workflow

In repoze.workflow.zcml.register_workflow (that registers the
workflows) I just added a statement that prints the result of the
zope.component.getSiteManager method.

This is what happends, according to my understanding (please correct
me if I'm wrong):

- config.hook_zca sets up Pyramids get_current_registry as hook for
zope.component.getSiteManager - that isn't committed/activated since
config.end() isn't run
- When i include the workflow, it's set up in the registry name
'global' (which is not the same as the global site manager which is
called 'base', as far as i can see)
- When configuration is done, config.end() commits the configuration
changes, and hooks get_current_registry from Pyramid as the method to
use for getSiteManager.

This has the effect that all methods, including repoze.workflow now
use the local registry. (In my case named the same as the app,
'voteit.core')
This also means that all configuration that was loaded before
config.end() was run exists in a registry that no code will ever use.

Am I missing something here? If this is the case, it would never be
possible to add any regular zope apps to pyramid during the config-
stage. Is there any way around this?
(Note: If i register the global registry as manager, the same problem
will occur since that change will be committed when config.end() is run)

Cheers,
Robin


12 jun 2011 kl. 02.55 skrev Chris McDonough:

> config.hook_zca() works too without requiring using the global
> registry:
>
> <http://docs.pylonsproject.org/projects/pyramid/1.0/narr/zca.html#enabling-the-zca-global-api-by-using-hook-zca
> >
>
> - C
>

--
Betahaus
gsm: +46 70-333 00 10
web: http://www.betahaus.net

Reply all
Reply to author
Forward
0 new messages