加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 02:08:05 所属栏目:Windows 来源:网络整理
导读:我正在尝试在我的Plone站点上创建一个控制面板加载项,用于编辑作为字典类型的注册表记录. 我的目的是将“供应商类型”存储为注册表中的字典. 我在profiles / default中的registry.xml: registry record interface="gpcl.assets.suppliertypes.ISupplierType
我正在尝试在我的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>

我的界面和形式:

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()

我将它添加到我的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>

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

解决方法

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

它在这两篇文章中描述:

> http://blog.redturtle.it/plone.app.registry-how-to-use-it-and-love-it
> http://blog.redturtle.it/plone-registry-strikes-back

用两个词来说:使用schema.Tuple with schema.Object里面.为了保持使密钥唯一的dict行为,您必须提供自己的验证器.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读