我正在尝试覆盖用于相关项目的小部件(dexterity so z3cform),它来自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
答案 0 :(得分:0)
我曾使用此类覆盖小部件,以便为网络摄像头启用上传功能。我想你想要覆盖json的生成以使这个jQuery兼容。非常感谢你的工作。
以下是我的课程:http://pastie.org/7923172
希望它有所帮助。