gpt4 book ai didi

plone - 由于上下文为 NO_VALUE,词汇表不适用于collective.z3cform.datagridfield 的子对象模式

转载 作者:行者123 更新时间:2023-12-04 04:49:47 24 4
gpt4 key购买 nike

我正在研究使用 datagridfield 的内容类型。
在子对象中,我有一个带有自定义词汇表的选择字段。

词汇表在数据网格之外工作(如果我直接在内容类型的架构中使用它)。但是当我将它添加到子对象时,它不再起作用。

查看调试说明,我看到词汇表的上下文是 NO_VALUE。

有什么提示/方向可以使它起作用吗?

这是行不通的最简单模式(我认为):

# Import 
from zope import schema
from zope.interface import Interface

from plone.directives import form
from collective.z3cform.datagridfield import DataGridFieldFactory, DictRow

# The container
class IMenu(Interface):
dishes = schema.List(value_type=schema.TextLine())

# The vocabulary
@grok.provider(IContextSourceBinder)
def getDishes(context):
terms = [SimpleVocabulary.createTerm(dish, dish, dish) for dish in context.dishes]
return SimpleVocabulary(terms)

# The object line
class IOrderLine(Interface):
dish = schema.Choice(source=getDishes)
quantity = schema.Int()

# The object
class IOrder(Interface):
form.widget(dishes=DataGridFieldFactory)
dishes = schema.List(value_type=DictRow(schema=IOrderLine))

现在我将 Menu, Order 注册为灵巧内容类型,添加一个菜单并尝试在其中添加一个订单,我在 Order add View 上出现错误,这是回溯:
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
Module ZPublisher.Publish, line 46, in call_object
Module plone.z3cform.layout, line 66, in __call__
Module plone.z3cform.layout, line 50, in update
Module plone.dexterity.browser.add, line 112, 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 128, in update
Module z3c.form.form, line 134, in updateWidgets
Module z3c.form.field, line 277, in update
Module z3c.form.browser.multi, line 63, in update
Module z3c.form.browser.widget, line 171, in update
Module z3c.form.widget, line 477, in update
Module collective.z3cform.datagridfield.datagridfield, line 107, in updateWidgets
Module collective.z3cform.datagridfield.datagridfield, line 91, in getWidget
Module z3c.form.browser.widget, line 171, in update
Module z3c.form.object, line 217, in update
Module z3c.form.object, line 208, in updateWidgets
Module z3c.form.object, line 87, in update
Module plone.z3cform.patch, line 21, in BaseForm_update
Module z3c.form.form, line 150, in update
Module z3c.form.form, line 134, in updateWidgets
Module z3c.form.field, line 277, in update
Module z3c.form.browser.select, line 51, in update
Module z3c.form.browser.widget, line 171, in update
Module z3c.form.widget, line 220, in update
Module z3c.form.widget, line 214, 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 96, in ChoiceTerms
Module zope.schema._field, line 349, in bind
Module waga.game.core.content.interfaces, line 202, in getDishes
AttributeError: 'NO_VALUE' object has no attribute 'dishes'
> /home/quyetnd/Projects/waga.game.core/src/waga/game/core/content/interfaces.py(202)getDishes()
-> terms = [SimpleVocabulary.createTerm(dish, dish, dish) for dish in context.dishes]

上下文对象是一个实例。

最佳答案

这是 z3c.form 中的限制(至少在某些版本中,我认为它已在较新的版本中得到修复)。

我在 vocab 源函数中的丑陋解决方法:

 if not context:
context = getSite()
if not context:
# Form is rendered from console without HTTP request traversing, etc.
# and thread local site variable is not set
raise RuntimeError("Oh snap. Beer time.")

...

http://developer.plone.org/serving/traversing.html#using-getsite

关于plone - 由于上下文为 NO_VALUE,词汇表不适用于collective.z3cform.datagridfield 的子对象模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17607632/

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