3
我試圖重寫用於relateditems微件(靈巧所以z3cform)的新contenttreewidget這是從plone.formwidget.contenttree.widget進口MultiContentTreeWidget如何創建z3cform
我的問題是我不明白爲什麼我的示例試圖找到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