Plone 如何使用zope.schema将门户类型分组到类别中?

Plone 如何使用zope.schema将门户类型分组到类别中?,plone,zope,Plone,Zope,我需要创建一个Plone configlet来提供这种结构: types = { 'News articles': ['NewsMediaType', 'News Item'], 'Images': ['Image'], 'Pages': ['Page'] } 我制作了一个原型来展示我在表格中的想法: 因此,我需要将一些门户类型分组在一起,并让用户为这个组指定一个名称。我该怎么做?有什么想法吗 编辑: 我在这个问题上取得了很大的进步,但是当保存表单时,验证给了我一个

我需要创建一个Plone configlet来提供这种结构:

types = {
    'News articles': ['NewsMediaType', 'News Item'], 
    'Images': ['Image'],
    'Pages': ['Page']
}
我制作了一个原型来展示我在表格中的想法:

因此,我需要将一些门户类型分组在一起,并让用户为这个组指定一个名称。我该怎么做?有什么想法吗

编辑:

我在这个问题上取得了很大的进步,但是当保存表单时,验证给了我一个错误

    # -*- coding: utf-8 -*-
from plone.theme.interfaces import IDefaultPloneLayer

from z3c.form import interfaces

from zope import schema
from zope.interface import Interface

from plone.registry.field import PersistentField

class IThemeSpecific(IDefaultPloneLayer):
    """  """

class PersistentObject(PersistentField, schema.Object):
    pass

class IAjaxsearchGroup(Interface):
    """Global akismet settings. This describes records stored in the
    configuration registry and obtainable via plone.registry.
    """
    group_name = schema.TextLine(title=u"Group Name",
                                  description=u"Name for the group",
                                  required=False,
                                  default=u'',)

    group_types = schema.List(title=u"Portal Types",
                    description=u"Portal Types to search in this group",
                    value_type =schema.Choice(
                        title=u"Portal Types",
                        vocabulary=u"plone.app.vocabularies.ReallyUserFriendlyTypes",
                        required=False,
                    ),
                    required=False,)

class IAjaxsearchSettings(Interface):
    """Global akismet settings. This describes records stored in the
    configuration registry and obtainable via plone.registry.
    """
    group_info = schema.Tuple(title=u"Group Info",
                                  description=u"Informations of the group",
                                  value_type=PersistentObject(IAjaxsearchGroup, required=False),
                                  required=False,)

-

这是CRUD(创建-读取-更新-删除)模式

plone.z3cform
包专门支持这种表单。为类型组定义架构:

 class IAJAXTypesGroup(interface):
     name = ...
     types = ...
然后使用:


组需要有一个id,项目按
get\u items()
返回它们的顺序显示。

我为factory创建了类

class AjaxsearchGroup(object):
    """
    group of config
    """
    zope.interface.implements(IAjaxsearchGroup)

registerFactoryAdapter(IAjaxsearchGroup, AjaxsearchGroup)
要使用设置

# get groups config
registry = queryUtility(IRegistry)
settings = registry.forInterface(IAjaxsearchSettings, check=False)

for config in settings.group_info:
     types[config.group_name] = config.group_types

多谢各位

你真的不应该在你的问题上添加你的解决方案。您可以在下面添加答案;这样你的问题就可以被其他人重复使用,人们也可以给你的答案投票。谢谢你的提示。我又作了一个回答:)
class AjaxsearchGroup(object):
    """
    group of config
    """
    zope.interface.implements(IAjaxsearchGroup)

registerFactoryAdapter(IAjaxsearchGroup, AjaxsearchGroup)
# get groups config
registry = queryUtility(IRegistry)
settings = registry.forInterface(IAjaxsearchSettings, check=False)

for config in settings.group_info:
     types[config.group_name] = config.group_types