添加“标签” ATEvent 方法
我使用 archetypes.schemaextender 来扩展 ATEvent 的架构以添加 ImageField。
那行得通。
现在,我想将“tag”方法添加到 ATEvent 中,以便使用缩放图像的“新”方式。
所以我这样做: 在文件extender.py中:
from Products.CMFCore.permissions import View
from AccessControl import ClassSecurityInfo
from zope.interface import Interface
class IImageExtender(Interface):
""" """
def tag():
""" """
class ImageExtender(object):
""" """
implements(IImageExtender)
security = ClassSecurityInfo()
def __init__(self, context):
self.context = context
security.declareProtected(View, 'tag')
def tag(self, **kwargs):
"""Generate image tag using the api of the ImageField
"""
return self.getField('image').tag(self, **kwargs)
之后在configure.zcml中:
<adapter for="Products.ATContentTypes.interface.IATEvent"
provides=".extender.IImageExtender"
factory=".extender.ImageExtender" />
但它不起作用。 我收到这些错误:
Module zope.tales.pythonexpr, line 59, in __call__
- __traceback_info__: ( path('nocall:item_object/tag')(scale=size, css_class='tileImage'))
Module <string>, line 1, in <module>
Module zope.tales.pythonexpr, line 77, in __call__
Module zope.tales.expressions, line 217, in __call__
Module zope.tales.expressions, line 194, in _eval
Module zope.tales.expressions, line 217, in __call__
Module zope.tales.expressions, line 194, in _eval
Module zope.tales.expressions, line 124, in _eval
Module zope.pagetemplate.engine, line 66, in __call__
Module zope.traversing.adapters, line 136, in traversePathElement
- __traceback_info__: (<ATEvent at /Plone/manifestations/visites-conferences/conf>, 'tag')
Module zope.traversing.adapters, line 50, in traverse
- __traceback_info__: (<ATEvent at /Plone/manifestations/visites-conferences/conf>, 'tag', [])
LocationError: (<ATEvent at /Plone/manifestations/visites-conferences/conf>, 'tag')
有什么线索吗? 谢谢。
I use archetypes.schemaextender to extend the schema of ATEvent in order to add an ImageField.
That works.
Now, I want to add the "tag" method to the ATEvent in order to use the "new" way of scaling images.
So I do this :
In a file extender.py :
from Products.CMFCore.permissions import View
from AccessControl import ClassSecurityInfo
from zope.interface import Interface
class IImageExtender(Interface):
""" """
def tag():
""" """
class ImageExtender(object):
""" """
implements(IImageExtender)
security = ClassSecurityInfo()
def __init__(self, context):
self.context = context
security.declareProtected(View, 'tag')
def tag(self, **kwargs):
"""Generate image tag using the api of the ImageField
"""
return self.getField('image').tag(self, **kwargs)
After that in the configure.zcml:
<adapter for="Products.ATContentTypes.interface.IATEvent"
provides=".extender.IImageExtender"
factory=".extender.ImageExtender" />
But it doesn't work.
I get those errors :
Module zope.tales.pythonexpr, line 59, in __call__
- __traceback_info__: ( path('nocall:item_object/tag')(scale=size, css_class='tileImage'))
Module <string>, line 1, in <module>
Module zope.tales.pythonexpr, line 77, in __call__
Module zope.tales.expressions, line 217, in __call__
Module zope.tales.expressions, line 194, in _eval
Module zope.tales.expressions, line 217, in __call__
Module zope.tales.expressions, line 194, in _eval
Module zope.tales.expressions, line 124, in _eval
Module zope.pagetemplate.engine, line 66, in __call__
Module zope.traversing.adapters, line 136, in traversePathElement
- __traceback_info__: (<ATEvent at /Plone/manifestations/visites-conferences/conf>, 'tag')
Module zope.traversing.adapters, line 50, in traverse
- __traceback_info__: (<ATEvent at /Plone/manifestations/visites-conferences/conf>, 'tag', [])
LocationError: (<ATEvent at /Plone/manifestations/visites-conferences/conf>, 'tag')
Any clues ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这里的问题是您试图在 ATEvent 上调用“标签”
对象,但该方法是在 ATEvent 对象的适配器上定义的。您需要能够调用 IImageExtender(item).tag()
不幸的是,受限的 python 阻止您直接在页面模板中执行此操作,因此您最好的选择是为扩展 ATEvent 创建一个 BrowserView,以提供对适配器的访问。
I believe the problem here is that you are trying to call 'tag' on the ATEvent
Object, but the method is defined on an adapter for the ATEvent Object. You need to be able to call IImageExtender(item).tag()
Unfortunately, restricted python prevents you from doing this directly in a page template, so your best bet will be to create a BrowserView for your extended ATEvent that provides access to the adapter.