Использование schemaextender для расширения класса ATEvent - PullRequest
2 голосов
/ 30 сентября 2011

Я использовал 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

1 Ответ

1 голос
/ 30 сентября 2011

Попробуйте использовать слой браузера и реализовать IBrowserLayerAwareExtender целое число ISchemaExtender:

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

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

Это гарантирует, что схема будет расширена только после установки вашего продукта. Вообще говоря, всегда рекомендуется поддерживать изоляцию настроек с фактическим экземпляром plone.

...