使用 schemaextender 扩展 ATEvent 类

发布于 2024-12-07 11:16:52 字数 3047 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霓裳挽歌倾城醉 2024-12-14 11:16:53

尝试使用 browserlayer 并实现 IBrowserLayerAwareExtender< /code> 而不是 ISchemaExtender

...
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender
from my.product.browser.interfaces.IMyProductLayer

class EventExtender(object):
    adapts(IATEvent)
    implements(IBrowserLayerAwareExtender)
    layer = IMyProductLayer
    ...

这可确保仅在安装产品时才扩展架构。一般来说,始终建议保持自定义与实际克隆实例的隔离。

Try to use a browserlayer and to implement IBrowserLayerAwareExtender intead of ISchemaExtender:

...
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender
from my.product.browser.interfaces.IMyProductLayer

class EventExtender(object):
    adapts(IATEvent)
    implements(IBrowserLayerAwareExtender)
    layer = IMyProductLayer
    ...

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文