首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Plone dexterity RelationList的动态源

Plone dexterity RelationList的动态源
EN

Stack Overflow用户
提问于 2012-09-06 18:34:11
回答 1查看 956关注 0票数 4

我有一个Plone (4.2)表单,它被弄糊涂了。我想有一个特定领域的动态源。架构的相关部分:

代码语言:javascript
复制
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
    )

这将导致:

代码语言:javascript
复制
ValueError: Invalid clone vocabulary

我尝试了plone dexterity developer manual中描述的每一种变体。将装饰器与RelationChoicesource属性结合使用的方法(请参见上文)和一个命名词汇类,两者都具有相同的结果。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-06 18:50:25

我应该调用ObjPathSourceBinder对象,而不是调用帮助。此代码的工作方式与预期一致:

代码语言:javascript
复制
@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) 

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12298136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档