【发布时间】:2015-03-13 23:56:29
【问题描述】:
我尝试在 Plone 4.3.3 下,在我的一个产品中自定义原型内容类型的类方法。
我有一个产品bsw.produit_1,其内容类型为MyContent,定义如下:
class MyContent(base.ATCTContent):
implements(IMyContent)
meta_type = "MyContent"
schema = MyContent`
def ma_fonction(self):
......
return res
我想在另一个产品中修改我的函数ma_fonction 的代码。我曾尝试使用适配器并遵循 plone 文档,但没有成功。
我希望自定义功能的类:
class CustomClass(object):
""" """
implements(IMyContent)
adapts(IMyContent)
def at_post_payment_script(self, obj_transaction):
""" """
......
# My new code
return res
我声明适配器的configure.zcml:
<adapter for="bsw.produit_1.content.mycontent.MyContent"
provides="bsw.produit_1.interfaces.IMyContent"
factory=".customclass.CustomClass" />
在我的 zcml 声明中,我还尝试将 archetypes.schemaextender.interfaces.ISchemaExtender 设置为 provides 或将接口 IMyContent 设置为 for 而不是类。
这些都不起作用,每次都不会执行自定义代码。有人对此有解决方案吗?
【问题讨论】:
-
我已尽我所能翻译成英文,我想这是您的问题被标记为“不清楚您在问什么”的原因之一。随意改进我的翻译,我希望我正确地表达了你的意图。
-
当您说“我希望自定义函数的类:...”时,我不明白您的意思。您的范围不是简单地覆盖原始方法
MyContent.ma_fonction吗? -
@keul:原来是“定制器”,我可能应该将其渲染为“更改”。我不确定为什么 sn-ps 中有两个不同的方法名称,不过,也许 Sebastien 可以帮助我们。
-
@keul:
ma_fonction是一种原型方法,在 plone 文档中它说使用适配器来覆盖原型方法。你知道另一种覆盖原型方法的方法吗? -
@Sebastien 我认为您误解了文档中的某些内容。
标签: adapter plone archetypes plone-4.x