4

我有一个 grokked 的 Plone (4.2) 表格。我想有一个特定领域的动态来源。架构的相关部分:

from plone.directives import form
from z3c.relationfield.schema import RelationList, RelationChoice
from five import grok
from plone.formwidget.contenttree import ObjPathSourceBinder


@grok.provider(ISourceContextBinder)
def availableAttachments(context)
    return ObjPathSourceBinder()


class IEmailFormSchema(form.Schema):

    attachments = RelationList(
        title = _(u'Attachments'),
        description = _(u'Select and upload attachments.'),
        default = [],
        value_type = RelationChoice(
                    title =_(u"attachment"),
                    default = [],
                    # source = ObjPathSourceBinder() # this works
                    source = availableAttachments),  # should do the same, but doesn't

        required = False
    )

这将导致:

ValueError: Invalid clone vocabulary

我尝试了plone dexterity 开发人员手册中描述的所有变体。带有装饰器的方法与(见上文)的source属性RelationChoice和命名的 Vocabulary 类的组合具有相同的结果。

4

1 回答 1

3

我应该打电话给ObjPathSourceBinder对象,而不是寻求帮助。此代码按预期工作:

@grok.provider(IContextSourceBinder)
def availableAttachments(context):

    path = '/'.join(context.getTmp_folder().getPhysicalPath())
    query = { "portal_type" : ("File","Image"),
              "path": {'query' :path } 
             }

    return ObjPathSourceBinder(navigation_tree_query = query).__call__(context) 

结合我的问题中的模式代码。

于 2012-09-06T10:50:24.803 回答