1

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

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传递给词汇调用的是图块的数据字典。SearchableTextSourceBinder在另一个领域使用时也会发生这种情况:

source=SearchableTextSourceBinder( {'is_folderish': True}, default_query='path:' ) 这使得 plone.app.vocabularies.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
4

1 回答 1

1

我不知道,如果它是设计使然,但是当编辑持久性磁贴时,上下文相关词汇将在没有任何采集包装的情况下获得其上下文(持久性磁贴数据字典)。因此,所有依赖于获取的查找都将失败。

您可以尝试使用或修复您的词汇表以使用门户根目录作为getToolByName-looksup的上下文。plone.api.portal.get()zope.component.hooks.getSite()

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

于 2013-05-23T07:55:24.157 回答