[Grok-dev] five.grok.subscribe doesn't work

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Feb 12 04:42:52 EST 2009


On Thu, Feb 12, 2009 at 10:29 AM, Vincent Fretin
<vincent.fretin at gmail.com> wrote:
> Hi,
>
> I try to use grok.subscribe to register my subscriber. I did the following:
> viewlets.py:
> -------------------------------------------------
> from five import grok
> from zope.lifecycleevent.interfaces import IObjectCreatedEvent
> from Products.ATContentTypes.interface.document import IATDocument
>
> grok.subscribe(IATDocument, IObjectCreatedEvent)
> def documentCreated(obj, event):
>    print "Document created", obj.id
> -------------------------------------------------
>
> configure.zcml:
> -------------------------------------------------
> <configure
>    xmlns="http://namespaces.zope.org/zope"
>    xmlns:grok="http://namespaces.zope.org/grok">
>  <include package="five.grok" />
>  <grok:grok package=".viewlets" />
> </configure>
> -------------------------------------------------
>
> My subscribr is never executed.
> I have viewlets in this module, and there are grokked, no problem.
>
>
> The following works:
> viewlets.py:
> -------------------------------------------------
> def documentCreated(obj, event):
>    print "Document created", obj.id
> -------------------------------------------------
>
> configure.zcml:
> -------------------------------------------------
> <configure
>    xmlns="http://namespaces.zope.org/zope"
>    xmlns:grok="http://namespaces.zope.org/grok">
>  <include package="five.grok" />
>  <grok:grok package=".viewlets" />
>  <subscriber
>      for="Products.ATContentTypes.interface.document.IATDocument
>           zope.lifecycleevent.interfaces.IObjectCreatedEvent"
>      handler=".viewlets.documentCreated"
>  />
> </configure>
> -------------------------------------------------
>
> Do I have missed something?

Could you try:

  @grok.subscribe(IATDocument, IObjectCreatedEvent)
  def documentCreated(obj, event):
      print "Document created", obj.id

grok.subscribe it to be used a decorator. The "@" is the syntax for that.

regards,
jw


More information about the Grok-dev mailing list