Plone 控制面板的最佳实践
我正在开发一个 package,其中包含使用 plone.app.registry 创建的控制面板。我遵循了 Timo 的教程< /a> 但是,当尝试向其中添加附加记录时,我面临着臭名昭著的KeyError:没有记录的字段。
所以我有几个关于最佳实践的问题:
我的第一个问题是:软件包必须在卸载时删除它的注册表?
我在我的包的registry.xml中使用了这个:
<registry>
<records interface="collective.nitf.controlpanel.INITFSettings" />
</registry>
在metadata.xml上使用了这个:
<metadata>
<version>1</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
</metadata>
但是在卸载配置文件上添加delete =“true”似乎不起作用。我还尝试按名称列出所有记录,但没有成功,除非我在 ZMI 手动运行该步骤。
所以,我的第二个问题是:如何在卸载时优雅地删除控制面板记录?
为了测试记录是否在注册表中,我做了这样的事情:
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
# Set up the NITF settings registry
self.registry = Registry()
self.registry.registerInterface(INITFSettings)
def test_record_sections(self):
# Test that the sections record is in the control panel
record_sections = self.registry.records[
'collective.nitf.controlpanel.INITFSettings.sections']
self.failUnless('sections' in INITFSettings)
self.assertEquals(record_sections.value, set([]))
第三个问题可能是如何测试记录是否在安装时被删除。
还有其他推荐吗?
I'm working on a package that includes a control panel created using plone.app.registry. I followed Timo's tutorial but, when trying to add an additional record to it, I'm facing the infamous KeyError: a field for which there is no record.
So I have a couple of questions about best practices:
My first question is: a package must remove it's registry at uninstall time?
I used this in registry.xml of my package:
<registry>
<records interface="collective.nitf.controlpanel.INITFSettings" />
</registry>
and this on metadata.xml:
<metadata>
<version>1</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
</metadata>
But adding a delete="true" on the uninstall profile seems not to be working. I tried also by listing all records by name with no luck, unless I run the step manually at ZMI.
So, my second question is: how do I remove control panel records at uninstall time gracefully?
To test if a record is on the registry I do something like this:
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
# Set up the NITF settings registry
self.registry = Registry()
self.registry.registerInterface(INITFSettings)
def test_record_sections(self):
# Test that the sections record is in the control panel
record_sections = self.registry.records[
'collective.nitf.controlpanel.INITFSettings.sections']
self.failUnless('sections' in INITFSettings)
self.assertEquals(record_sections.value, set([]))
A third question could be how to test if a record was removed at unisntall time.
Any other recommendation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:我自己还没有直接在包中使用 plone.app.registry 。
是的。至少,对社区软件包的作者的期望似乎是合理的。我希望 plone.app.registry 不会因为旧的已删除软件包中丢失的内容而绊倒,就像它在这里所做的那样,但这可能很棘手。
在大多数 GenericSetup 文件中,
remove="True"
有效。不确定这个具体案例。Note: I have not used plone.app.registry myself directly in a package yet.
Yes. It at least seems reasonable to expect this from authors of community packages. I would hope that plone.app.registry does not trip over missing stuff from old removed packages, like it seems to be doing here, but that may be tricky.
In most GenericSetup files
remove="True"
works. Not sure about this specific case.我不参与卸载时删除内容,因为有时您不想在重新安装时丢失配置...提供一种清理注册表的方法对于站点管理员来说应该更好。在您不关心丢失数据的测试实例上进行测试。
第二个问题已经由 maurits 回答了,所以你应该关心拼写错误:
delete="true" != "remove="True"
I'm not part of remove things on uninstall time because some time you don't want to lose your configuration at re install... providing a way to cleanup the registry should be better for administrator of the site. Do test on a test instance where you don't care to lost your data.
The second question is already answered by maurits, so you should care about typo:
delete="true" != "remove="True"