5

我需要用第二个产品扩展一个 Plone 产品 (Products.Poi)。在扩展产品中,我需要覆盖原始的订阅者事件。我试图在 override.zcml 中订阅一个具有相同名称的事件,但第二个事件不覆盖第一个事件,但所有两个事件都被执行。

这里http://plone.org/products/dexterity/documentation/manual/five.grok/core-components/events似乎是不可能的:

与适配器不同,您不能通过使用更具体的接口来覆盖事件订阅者。触发事件时,将执行每个适用的事件订阅者。

有人有诀窍吗?

谢谢亚历克斯

4

2 回答 2

6

Simone Orsi 给了我一个解决方案:z3c.unconfigure

本产品允许禁用 zcml 配置。

为了使用它,我在我的扩展 Poi 产品上执行了这个步骤:

  1. 在 setup.py 中添加了“z3c.unconfigure”作为 install_requires
  2. 使用 update_tracker_watchers 的新定义创建 event.py
  3. 在 overrides.zcml 添加此行以取消配置 Products.Poi.events.update_tracker_watchers 并注册我的新事件

<include package="z3c.unconfigure" file="meta.zcml" />
<unconfigure>
    <subscriber
        for="Products.Poi.interfaces.ITracker
                  Products.Archetypes.interfaces.IObjectEditedEvent"
        handler="Products.Poi.events.update_tracker_watchers"
    />
</unconfigure>
<subscriber
    for="Products.Poi.interfaces.ITracker
              Products.Archetypes.interfaces.IObjectEditedEvent"
    handler=".events.update_tracker_watchers"
/>

于 2013-01-27T17:33:45.170 回答
3

当你指定了 overrides.zcml 时,你还需要在 buildout 中注册 zcml 覆盖吗?看看: http: //developer.plone.org/components/zcml.html ?highlight=zcml#overrides 它会是这样的:zcml = my.package-overrides

此外,您可以尝试使用 z3c.unconfigure 包:http ://pypi.python.org/pypi/z3c.unconfigure

于 2013-01-27T13:20:38.697 回答