gpt4 book ai didi

plone - Plone 灵巧关系列表的动态源

转载 作者:行者123 更新时间:2023-12-01 19:34:15 26 4
gpt4 key购买 nike

我有一个 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 RelationChoice 的属性(见上文)和一个命名的 Vocabulary 类都具有相同的结果。

最佳答案

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

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

关于plone - Plone 灵巧关系列表的动态源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12298136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com