3

我正在尝试覆盖用于相关项目的小部件(敏捷性所以 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

4

1 回答 1

0

I once overrode the widget with this class to enable an upload ability for a webmailer. I think you want to override the generation of the json to make this jQuery compatible. Thanks a lot for that work.

Here is my class: http://pastie.org/7923172

Hope it helps.

于 2013-05-17T22:28:59.893 回答