1

この種の構造を提供するPlone構成レットを作成する必要があります。

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
4

2 に答える 2

1

それが CRUD (作成-読み取り-更新-削除) パターンです。

このplone.z3cformパッケージは、まさにそのようなフォームをサポートしています。タイプ グループのスキーマを定義します。

 class IAJAXTypesGroup(interface):
     name = ...
     types = ...

次にCRUD フォームを使用します。

from plone.z3cform.crud import crud

class AJAXGroupsCRUDForm(crud.CrudForm):
    update_schema = IAJAXTypesGroup

    def get_items(self):
        # return a sequence of (id, IAJAXTypesGroup-implementer) tuples
        return self.context.getGroups()

    def add(self, data):
        # return a new IAJAXTypesGroup implementer; a IObjectCreatedEvent is generated
        # alternatively, raise zope.schema.ValidationError
        id = self.context.createGroup(**data)
        return self.context.getGroup(id)

    def remove(self, (id, item)):
        # Remove this specific entry from your list
        self.context.deleteGroup(id)

グループには ID が必要です。アイテムは、get_items()返された順に表示されます。

于 2013-02-15T11:20:18.057 に答える
1

ファクトリのクラスを作成しました

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

本当にありがとうございました!

于 2013-02-22T18:55:49.597 に答える