使用 schemaextender 扩展 ATEvent 类
我使用 schemaextender 来扩展 ATEvents,以便它们包含一个用于切换事件时间和 iCal 显示的复选框。
它在现有网站上工作正常,但当我尝试创建一个新网站时,我收到错误“ValueError:nextPreviousEnabled.default_method既不是方法,也不是可调用的方法”
有什么想法吗?扩展代码:
from Products.Archetypes.public import BooleanField
from archetypes.schemaextender.field import ExtensionField
class DisplayEventTimeField(ExtensionField, BooleanField):
"""A toggle to indicate whether the view should display the time or just the date of this community event"""
from zope.component import adapts
from zope.interface import implements
from archetypes.schemaextender.interfaces import ISchemaExtender
from Products.Archetypes.public import BooleanWidget
from Products.ATContentTypes.interface import IATEvent
class EventExtender(object):
adapts(IATEvent)
implements(ISchemaExtender)
fields = [
DisplayEventTimeField("display_event_time",
widget = BooleanWidget(
label="Display event time",
description="Turn this off to show only the event date (also disables iCal/vCal)",
defult=True)),
]
def __init__(self, context):
self.context = context
def getFields(self):
return self.fields
和完整的回溯:
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFPlone.browser.admin, line 201, in __call__
Module Products.CMFPlone.factory, line 83, in addPloneSite
Module Products.GenericSetup.tool, line 330, in runAllImportStepsFromProfile
- __traceback_info__: profile-Products.CMFPlone:plone-content
Module Products.GenericSetup.tool, line 1085, in _runImportStepsFromContext
Module Products.GenericSetup.tool, line 999, in _doRunImportStep
- __traceback_info__: plone-content
Module Products.CMFPlone.setuphandlers, line 486, in importContent
Module Products.CMFPlone.setuphandlers, line 234, in setupPortalContent
Module Products.CMFPlone.utils, line 306, in _createObjectByType
Module Products.CMFCore.TypesTool, line 554, in _constructInstance
Module Products.ATContentTypes.content.topic, line 6, in addATTopic
Module Products.Archetypes.BaseFolder, line 96, in manage_afterAdd
Module Products.Archetypes.BaseObject, line 159, in manage_afterAdd
- __traceback_info__: (<ATTopic at /Plone/news/aggregator>, <ATTopic at /Plone/news/aggregator>, <App.ProductContext.__FactoryDispatcher__ object at 0x1071bfd50>)
Module Products.Archetypes.BaseObject, line 174, in initializeLayers
Module Products.Archetypes.Schema, line 338, in initializeLayers
Module Products.Archetypes.Storage, line 161, in initializeField
Module Products.Archetypes.Field, line 591, in getDefault
ValueError: nextPreviousEnabled.default_method is neither a method of <class 'Products.ATContentTypes.content.topic.ATTopic'> nor a callable
I have used schemaextender to extend ATEvents so that they include a checkbox for toggling the time and iCal display for events.
It works fine on an existing site but when I try and create a new site i get an error "ValueError: nextPreviousEnabled.default_method is neither a method of nor a callable"
Any ideas? The extension code:
from Products.Archetypes.public import BooleanField
from archetypes.schemaextender.field import ExtensionField
class DisplayEventTimeField(ExtensionField, BooleanField):
"""A toggle to indicate whether the view should display the time or just the date of this community event"""
from zope.component import adapts
from zope.interface import implements
from archetypes.schemaextender.interfaces import ISchemaExtender
from Products.Archetypes.public import BooleanWidget
from Products.ATContentTypes.interface import IATEvent
class EventExtender(object):
adapts(IATEvent)
implements(ISchemaExtender)
fields = [
DisplayEventTimeField("display_event_time",
widget = BooleanWidget(
label="Display event time",
description="Turn this off to show only the event date (also disables iCal/vCal)",
defult=True)),
]
def __init__(self, context):
self.context = context
def getFields(self):
return self.fields
and the full traceback:
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFPlone.browser.admin, line 201, in __call__
Module Products.CMFPlone.factory, line 83, in addPloneSite
Module Products.GenericSetup.tool, line 330, in runAllImportStepsFromProfile
- __traceback_info__: profile-Products.CMFPlone:plone-content
Module Products.GenericSetup.tool, line 1085, in _runImportStepsFromContext
Module Products.GenericSetup.tool, line 999, in _doRunImportStep
- __traceback_info__: plone-content
Module Products.CMFPlone.setuphandlers, line 486, in importContent
Module Products.CMFPlone.setuphandlers, line 234, in setupPortalContent
Module Products.CMFPlone.utils, line 306, in _createObjectByType
Module Products.CMFCore.TypesTool, line 554, in _constructInstance
Module Products.ATContentTypes.content.topic, line 6, in addATTopic
Module Products.Archetypes.BaseFolder, line 96, in manage_afterAdd
Module Products.Archetypes.BaseObject, line 159, in manage_afterAdd
- __traceback_info__: (<ATTopic at /Plone/news/aggregator>, <ATTopic at /Plone/news/aggregator>, <App.ProductContext.__FactoryDispatcher__ object at 0x1071bfd50>)
Module Products.Archetypes.BaseObject, line 174, in initializeLayers
Module Products.Archetypes.Schema, line 338, in initializeLayers
Module Products.Archetypes.Storage, line 161, in initializeField
Module Products.Archetypes.Field, line 591, in getDefault
ValueError: nextPreviousEnabled.default_method is neither a method of <class 'Products.ATContentTypes.content.topic.ATTopic'> nor a callable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 browserlayer 并实现
IBrowserLayerAwareExtender< /code> 而不是
ISchemaExtender
:这可确保仅在安装产品时才扩展架构。一般来说,始终建议保持自定义与实际克隆实例的隔离。
Try to use a browserlayer and to implement
IBrowserLayerAwareExtender
intead ofISchemaExtender
:This ensure that the schema is extended only when your product is installed. Generally speaking it's always recommended to maintain the isolation of customizations to the actual plone instance.