我需要創建一個Plone configlet會,提供這種結構:如何使用zope.schema將門戶類型分組到類別中?
types = {
'News articles': ['NewsMediaType', 'News Item'],
'Images': ['Image'],
'Pages': ['Page']
}
我做了一個原型,以顯示我在想什麼有形式:
所以我需要將一些portal_types分組在一起,並讓用戶爲該組分配一個名稱。我怎樣才能做到這一點?有任何想法嗎?
編輯:
我提出的問題有很大的進步,但保存表單時,驗證給我一個錯誤
# -*- 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,)
-
from plone.app.registry.browser import controlpanel
from collective.ajaxsearch.interfaces.interfaces import IAjaxsearchSettings
from collective.ajaxsearch.interfaces.interfaces import IAjaxsearchGroup
from z3c.form.object import registerFactoryAdapter
class AjaxsearchSettingsEditForm(controlpanel.RegistryEditForm):
schema = IAjaxsearchSettings
label = u"Ajaxsearch settings"
description = u""""""
def updateFields(self):
super(AjaxsearchSettingsEditForm, self).updateFields()
def updateWidgets(self):
super(AjaxsearchSettingsEditForm, self).updateWidgets()
class AjaxsearchSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
form = AjaxsearchSettingsEditForm
你真的不應該將你的解決方案添加到你的問題。您可以在下面添加一個答案;這樣你的問題就可以重新用於其他人,而且人們也可以給你答案投票。 – 2013-02-22 13:23:32
謝謝你的提示。我做了另一個回答 http://stackoverflow.com/a/15031254/1935882 :) – 2013-03-07 19:38:56