0

我正在编写一个升级步骤,将记录添加到将在控制面板配置中使用的注册表。

我首先添加了一个带有registry.xml文件的配置文件,但后来我应该有一种方法可以以编程方式完成此操作,以避免为此创建和注册 GS 配置文件。

我阅读了plone.registtry的文档,根据它,List的value_type属性可能只包含持久字段,所以我得出了以下代码:

from collective.cover import _
from collective.cover.config import DEFAULT_AVAILABLE_TILES
from collective.cover.config import PROJECTNAME
from plone.registry import field
from plone.registry import Record
from plone.registry.interfaces import IRegistry
from zope.component import getUtility

import logging


def register_available_tiles_record(context, logger=None):
    """Handler for upgrade step from 2 to 3; adds the 'available_tiles' record
    to the registry.
    """
    if logger is None:
        logger = logging.getLogger(PROJECTNAME)

    registry = getUtility(IRegistry)
    record = 'collective.cover.controlpanel.ICoverSettings.available_tiles'

    if record not in registry.records:
        available_tiles = field.List(
            title=_(u"Available tiles"),
            description=_(u"This tiles will be available for layout creation."),
            required=True,
            default=DEFAULT_AVAILABLE_TILES,
            value_type=field.Choice(
                vocabulary=u'collective.cover.EnabledTiles'),
        )

        registry.records[record] = Record(available_tiles)
        logger.info("'available_tiles' record was added to the registry")
    else:
        logger.info("'available_tiles' record already exists in the registry")

但是当我运行处理程序时,我收到以下错误:

Error in test test_from_2_to_3 (collective.cover.tests.test_upgrades.UpgradeStepsTestCase)
Traceback (most recent call last):
  File "/home/hvelarde/buildout.python/parts/opt/lib/python2.7/unittest/case.py", line 327, in run
    testMethod()
  File "/home/hvelarde/collective/cover/src/collective/cover/tests/test_upgrades.py", line 35, in test_from_2_to_3
    register_available_tiles_record(self.portal)
  File "/home/hvelarde/collective/cover/src/collective/cover/upgrades.py", line 31, in register_available_tiles_record
    vocabulary=u'collective.cover.EnabledTiles'),
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_field.py", line 458, in __init__
    super(AbstractCollection, self).__init__(**kw)
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_bootstrapfields.py", line 306, in __init__
    super(MinMaxLen, self).__init__(**kw)
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_bootstrapfields.py", line 157, in __init__
    self.default = default
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_bootstrapfields.py", line 53, in __set__
    inst.validate(value)
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_bootstrapfields.py", line 182, in validate
    self._validate(value)
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_field.py", line 476, in _validate
    errors = _validate_sequence(self.value_type, value)
  File "/home/hvelarde/.buildout/eggs/zope.schema-4.2.2-py2.7.egg/zope/schema/_field.py", line 438, in _validate_sequence
    value_type.validate(item)
AttributeError: 'InterfaceConstrainedProperty' object has no attribute 'validate'

我在这里做错了什么?

4

1 回答 1

0

在我看来,这是 plone.registry 的限制/错误;我最终在升级步骤中进行了正常的注册表注册。

任何有兴趣的人都可以在这里看到:https ://github.com/collective/collective.cover/commit/137211a84a575fc03fbb84e0cbd091bec85a6ab7

于 2013-04-29T21:10:59.640 回答