繁体   English   中英

如何获得一个RelationList来按object_provides进行过滤?

[英]How do I get a RelationList to filter by object_provides?

我在获取一个RelationList来显示我想要的小部件时遇到一些麻烦。 我所看到的行为对我来说没有意义:/ mysite / folder1 / foo-新内容,我要在其中创建关系/ mysite / folder2 / bar-我要链接的项目。

source=ObjPathSourceBinder(object_provides='foo.bar.IMyInterface')

尽管仅选择提供IMyInterface的内容,但无论界面如何,这似乎都能显示所有敏捷内容。

source=ObjPathSourceBinder(navigation_tree_query={'object_provides':'foo.bar.IMyInterface'}))

我不明白为什么这会导致不同的行为,但是却导致没有内容显示。 查询路径似乎有问题,因为它确实起作用:

source=ObjPathSourceBinder(navigation_tree_query={'path':{'query':'/mysite/folder2'},'object_provides':'foo.bar.IMyInterface'}))

但是,这并不理想,因为它需要知道路径。 我期望该行为仅显示类似文件夹的内容和提供我的界面的内容,而仅提供提供我的界面可选的内容。 那不可能吗?

我知道默认情况下不再支持关系https://pypi.python.org/pypi/plone.app.dexterity#relation-support-no-longer-included-default-default (我正在使用plone.app .dexterity 1.2.1和Plone 4.2)

另外,一个简单的select小部件就可以了,但是我无法获得任何默认的z3c.form小部件来与该字段正确配合使用(它们呈现的很好,但是没有可选内容)。 也许仅将常规z3c模式列表与词汇表(其中值是UID)一起使用,然后自己查找对象会更好?

我不确定之前做错了什么,但是我得到了下面的内容来处理一个简单的选择框(有序):从plone.directives的五个导入grok.directives从Products.CMFCore.utils的导入表单,从z3c.form的getToolByName导入.browser.orderedselect从z3c.relationfield.schema导入OrderedSelectFieldWidget导入zope.schema.interfaces的RelationChoice,Relation,RelationList从zope.schema.vocabulary导入IContextSourceBinder导入SimpleVocabulary,SimpleTerm

@grok.provider(IContextSourceBinder)
def possibleVals(context):
  catalog = getToolByName(context,'portal_catalog')
  brains = catalog(object_provides='foo.bar.IMyInterface')
  return SimpleVocabulary([SimpleTerm(value=b.getObject(),token=b.getPath(),title=b.Title) for b in brains])

...

form.widget(myfield=OrderedSelectFieldWidget)
myfield = RelationList(
    title=_(u'My field'),
    required=False,
    value_type=RelationChoice(title=_(u'My field'),
                              source=possibleVals),
    )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM