Plone-如何在注册表中为字典类型的记录创建控制面板?

Pat*_*ney 4 plone

我正在尝试在我的Plone站点上创建一个控制面板加载项,用于编辑作为字典类型的注册表记录.

我的目的是将"供应商类型"存储为注册表中的字典.

我在profiles/default中的registry.xml:

<registry>
    <record interface="gpcl.assets.suppliertypes.ISupplierTypes" field="supplier_types">
        <value>
            <element key="1">Distributor</element>
            <element key="2">Manufacturer</element>
            <element key="3">Service Provider</element>
        </value>
    </record>
</registry>
Run Code Online (Sandbox Code Playgroud)

我的界面和形式:

class ISupplierTypes(form.Schema):
    """ Define settings data structure
    """

    supplier_types = schema.Dict(title=u"Types of Suppliers",
                                 key_type=schema.Int(title=u"supplier_type_id"),
                                 value_type=schema.TextLine(title=u"supplier_type_name", 
                                                            required=False),
                                 required=False,
                                )

class SupplierTypesEditForm(RegistryEditForm):
    """
    Define form logic
    """
    schema = ISupplierTypes
    label = u"Types of Suppliers"

    description = u"Please enter types of suppliers"


class SupplierTypesView(grok.View):
    """
    View class
    """

    grok.name("supplier-types")
    grok.context(ISiteRoot)

    def render(self):
        view_factor = layout.wrap_form(SupplierTypesEditForm, ControlPanelFormWrapper)
        view = view_factor(self.context, self.request)
        return view()
Run Code Online (Sandbox Code Playgroud)

我将它添加到我的profiles/default中的controlpanels.xml和portal_quickinstaller中,我安装了产品,控制面板确实显示在附加组件中并显示显示默认值的字段.不幸的是,当我尝试添加,编辑或删除时,会显示一条错误消息,指出"包含的类型错误".我认为我在创建控制面板的方法上错了.

为dict类型的记录创建控制面板的正确方法是什么?

具有讽刺意味的是,在视图类的render方法中,我试图看看是否可以打印记录(在此处找到了如何执行此操作:https://pypi.python.org/pypi/plone.app.registry#using-the -records-proxy)我能够,作为一个dict对象出现.我还能够以编程方式将新的"元素"添加到记录中.

至于我想要使用dict类型,我确实计划利用键值,这就是我想使用字典类型的原因.

如果我使用不正确的术语,我道歉.

先感谢您.

编辑:

我正在使用Plone 4.3.2.

编辑:

对不起我错了.我找到了追溯.

2014-08-20 13:13:07 ERROR Zope.SiteErrorLog 1408554787.930.279058908095
http://localhost:8080/GPCLAssetTracker/@@supplier-types/@@z3cform_validate_field

Traceback (innermost last):
    Module ZPublisher.Publish, line 138, in publish
    Module ZPublisher.mapply, line 72, in mapply
    Module ZPublisher.Publish, line 53, in missing_name
    Module ZPublisher.HTTPResponse, line 741, in badRequestError
    BadRequest:   <h2>Site Error</h2>
    <p>An error was encountered while publishing this resource.
    </p>
    <p><strong>Invalid request</strong></p>

    The parameter, <em>fname</em>, was omitted from the request.<p>Make sure to specify all        required parameters, and try the request again.</p>
<hr noshade="noshade"/>

<p>Troubleshooting Suggestions</p>

<ul>
<li>The URL may be incorrect.</li>
<li>The parameters passed to this resource may be incorrect.</li>
<li>A resource that this resource relies on may be
    encountering an error.</li>
</ul>

<p>For more detailed information about the error, please
refer to the error log.
</p>

<p>If the error persists please contact the site maintainer.
Thank you for your patience.
</p>
Run Code Online (Sandbox Code Playgroud)

我也忘了提到,我使用的操作系统是Xubuntu.

keu*_*eul 6

您可以选择使用schema.Dict,但有时我会使用不同的方法.请记住,这将是危险的:您必须为加载项提供卸载步骤,否则如果稍后删除加载项,您的注册表将保持中断.

它在这两篇文章中描述:

在两个字:使用schema.Tupleschema.Object内.为了保持使密钥唯一的dict行为,您必须提供自己的验证器.

另一个好的方法(neved used)是文章"复杂的Plone注册表设置重新访问"中所描述的,但它似乎从网上消失了(......非常悲伤......).