GenericSetup:如果仍然需要从initialize()调用ToolInit,toolset.xml会完成什么任务
看来toolset.xml 只完成了一半。理想情况下,它应该能够消除 __init__.py 中的initialize() 中的 ToolInit 调用。但如果没有 ToolInit 调用,我无法在 ZMI 中显示工具图标。
It seems that toolset.xml goes only half way. Ideally it should be able to do away with the ToolInit call in initialize() in __init__.py. But I could not get the tool icon to show in the ZMI without the ToolInit call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
初始化函数中的 ToolInit 调用将工具类注册为可以添加到数据库中基于 OFS 的文件夹中的东西 - 主要是注册一个用于创建该类实例的工厂。这与 ContentInit 对普通内容类所做的操作基本相同。
一旦类被注册并且它的meta_type已知,类的实例就可以被添加到基于OFS的文件夹中。 GenericSetup 步骤负责管理持久内容,并可用于将工具实例添加到数据库。
如果我们想避免初始化函数中的代码,我们需要创建一些自定义 ZCML 指令,并在 configure.zcml 中使用它们来注册类型及其工厂。 Dexterity 已经走了这条路,但它不适用于基于原型的内容类型或工具等通用类。
The ToolInit call in the initialize function registers the tool class as something that can be added to OFS based folders in the database - primarily it register a factory for creating instances of the class. This is basically the same that ContentInit does for normal content classes.
Once the class is registered and its meta_type is known, instances of the class can be added to OFS based Folders. GenericSetup steps are responsible for managing persistent content and can be used to add tool instances to the database.
If we wanted to avoid the code in the initialize function, we would need to create some custom ZCML directives instead and use these in a configure.zcml to register the type and its factory. Dexterity has gone this route, but its not available for Archetypes based content types or general classes like tools.
toolset.xml 的目标是将工具实例化到数据库中。它还可以用来移除工具;例如,这在升级步骤中非常有用。
示例toolset.xml:
此示例toolset.xml 将在其上下文中将FooTool 类实例化为
portal_foo
,并删除任何具有idportal_spam
的对象(如果存在)。请注意,您可以在任何 GenericSetup 配置文件中使用toolset.xml,而不仅仅是在最初定义该工具的包中,例如,在您开发的站点的一般策略包中。
The goal of toolset.xml is to instantiate tools into the database. It can also be used to remove tools; this is very useful in upgrade steps for example.
Example toolset.xml:
This example toolset.xml would instantiate the FooTool class as
portal_foo
in it's context, and remove any object with idportal_spam
if present.Note that you can use a toolset.xml in any GenericSetup profile, not just in the package that defines the tool in the first place, for example, in general policy packages for a site you develop.