Plone灵活性RelationList的动态源

时间:2012-09-06 10:34:11

标签: plone grok z3c.form

我有一个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 developer manual中描述的每个变体。一个带有装饰器的方法,结合source的{​​{1}}属性(见上文)和一个名为Vocabulary类的方法都具有相同的结果。

1 个答案:

答案 0 :(得分:2)

我应该调用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) 

结合我的问题中的架构代码。