gpt4 book ai didi

plone - 如何为 z3cform 创建一个新的 contenttreewidget

转载 作者:行者123 更新时间:2023-12-04 23:53:57 25 4
gpt4 key购买 nike

我正在尝试覆盖用于 relateditems 的小部件(灵 active 所以 z3cform)这是 from plone.formwidget.contenttree.widget import MultiContentTreeWidget

我遇到的问题是我不明白为什么我的示例试图找到 IDataConverter 的组件,而 contenttree 小部件和它的父级没有 IDataConverter。

代码是:

#zope
from zope import interface
import z3c.form.interfaces
import z3c.form.widget
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

#plone
from plone.formwidget.contenttree.interfaces import IContentTreeWidget
from plone.formwidget.contenttree.widget import MultiContentTreeWidget
from plone.app.relationfield.widget import RelationListDataManager

#internal


class DatalistManager(RelationListDataManager):
pass


class IMultiDatalistWidget(IContentTreeWidget):
"""Datalist widget marker for z3c.form """


class MultiDatalistWidget(MultiContentTreeWidget):
interface.implementsOnly(IMultiDatalistWidget)
input_template = ViewPageTemplateFile('templates/datalist_input.pt')

klass = u'html5-datalist-multiselection-widget'
js_template = """\
(function($) {
$().ready(function() {
console.log('autocomplete ready ?');
});
})(jQuery);
"""

def js_extra(self):
return ""


@interface.implementer(z3c.form.interfaces.IFieldWidget)
def MultiDatalistFieldWidget(field, request):
"""IFieldWidget factory for DatalistWidget."""
return z3c.form.widget.FieldWidget(field, MultiDatalistWidget(request))

还有 zcml:

<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:z3c="http://namespaces.zope.org/z3c"
i18n_domain="collective.z3cform.html5widgets">

<include package="plone.app.relationfield" />

<!-- TRY TO OVERRIDE IRelationList default from plone.app.relationfield -->

<adapter factory=".widget_datalist.MultiDatalistFieldWidget"
for="z3c.relationfield.interfaces.IRelationList
.layer.Layer"
/>

</configure>

如果我正在尝试小部件,我有以下回溯:

Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module plone.z3cform.layout, line 66, in __call__
Module plone.z3cform.layout, line 50, in update
Module z3c.form.form, line 208, in update
Module plone.z3cform.patch, line 21, in BaseForm_update
Module z3c.form.form, line 150, in update
Module z3c.form.form, line 134, in updateWidgets
Module z3c.form.field, line 277, in update
Module z3c.formwidget.query.widget, line 183, in update
Module z3c.formwidget.query.widget, line 230, in updateQueryWidget
Module z3c.form.browser.checkbox, line 45, in update
Module z3c.form.browser.widget, line 170, in update
Module z3c.form.widget, line 221, in update
Module z3c.form.widget, line 130, in update
TypeError: ('Could not adapt', <MultiDatalistWidget 'form.widgets.relatedItems'>, <InterfaceClass z3c.form.interfaces.IDataConverter>)

您可以在 github 上找到存储库:https://github.com/toutpt/collective.z3cform.html5widgets

最佳答案

我曾经用这个类覆盖小部件以启用网络邮件程序的上传功能。我认为您想覆盖 json 的生成以使此 jQuery 兼容。非常感谢您所做的工作。

这是我的类(class):http://pastie.org/7923172

希望对您有所帮助。

关于plone - 如何为 z3cform 创建一个新的 contenttreewidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15643628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com