tile编辑查看词汇表的错误上下文

时间:2013-05-22 16:47:46

标签: plone

我有一个持久的磁贴,它有一个选择字段:

subjects = schema.List(
    title=_(u"Subjects"),
    value_type=schema.Choice(
        vocabulary='my.subjects'
    ),
)

但这在编辑视图渲染上失败了:

2013-05-22 18:37:56 ERROR Zope.SiteErrorLog 1369240676.330.546121806344 http://localhost:8082/plumi/@@edit-tile/tagcloud.tile/home-cloud
Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module plone.z3cform.layout, line 70, in __call__
  Module plone.z3cform.layout, line 54, in update
  Module plone.app.tiles.browser.edit, line 48, in update
  Module plone.app.tiles.browser.base, line 55, in update
  Module plone.z3cform.fieldsets.extensible, line 59, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 125, in update
  Module plone.app.tiles.browser.base, line 71, in updateWidgets
  Module z3c.form.field, line 275, in update
  Module z3c.form.browser.orderedselect, line 50, in update
  Module z3c.form.browser.widget, line 70, in update
  Module z3c.form.widget, line 199, in update
  Module z3c.form.widget, line 193, in updateTerms
  Module zope.component._api, line 107, in getMultiAdapter
  Module zope.component._api, line 120, in queryMultiAdapter
  Module zope.component.registry, line 238, in queryMultiAdapter
  Module zope.interface.adapter, line 532, in queryMultiAdapter
  Module z3c.form.term, line 174, in CollectionTerms
  Module zope.schema._field, line 352, in bind
  Module Zope2.App.schema, line 33, in get
  Module my.vocabularies, line 22, in __call__
  Module Products.CMFCore.utils, line 10, in check_getToolByName
  Module Products.CMFCore.utils, line 120, in getToolByName
  AttributeError: portal_catalog

这是因为传递给词汇表调用的context是tile的数据字典。在另一个字段中使用SearchableTextSourceBinder时也会发生这种情况:

source=SearchableTextSourceBinder( {'is_folderish': True}, default_query='path:' ) 这使plone.app.vocabularyies.catalog失败:

Module plone.app.vocabularies.catalog, line 237, in __call__
  Module plone.app.vocabularies.catalog, line 144, in __init__
  Module Products.CMFCore.utils, line 10, in check_getToolByName
  Module Products.CMFCore.utils, line 120, in getToolByName
AttributeError: portal_catalog

1 个答案:

答案 0 :(得分:1)

我不知道,如果它是按设计进行的,但是当编辑持久性磁贴时,上下文敏感词汇表将获得其上下文(持久磁贴数据字典)而不进行任何采集包装。因此,所有依赖于获取的查找都将失败。

您可以尝试修复词汇表,使用门户网站root作为getToolByName的上下文 - 使用plone.api.portal.get()zope.component.hooks.getSite()进行查找。

如果你真的需要当前的上下文,那么一个丑陋的方法就是获得zope.globalrequest.getRequest().get("PUBLISHED"),它应该是ZPublisher当前可发布的上下文。它通常是一个视图,但您可以从其获取链中获取上下文对象。当然,你应该采取这种方法非常防守。