词汇源,函数不可迭代,在Plone 4.1中具有灵巧性(Vocabulary source, function is not iterable, with dexterity in Plone 4.1)
我有一个自定义Dexterity内容类型,其中collective.z3c.datagridfield以下列方式定义:
class ILanguageRow(Interface): # Interface that defines a datagrid row. lang = schema.Choice( title=_(u'Language'), required=True, source=my_languages, default=u'en', ) (...)
@grok.provider(IContextSourceBinder) def languages(context): """ Return a vocabulary of language codes and translated language names. """ # z3c.form KSS inline validation hack if not ISiteRoot.providedBy(context): for item in getSite().aq_chain: if ISiteRoot.providedBy(item): context = item # retrieve the localized language names. request = getRequest() portal_state = getMultiAdapter((context, request), name=u'plone_portal_state') lang_items = portal_state.locale().displayNames.languages.items() # build the dictionary return SimpleVocabulary( [SimpleTerm(value=lcode, token=lcode, title=lname)\ for lcode, lname in sorted(lang_items) if lcode in config.CV_LANGS] )
在“编辑”和“添加表单”中,“选择”字段可正常工作。 但是当我尝试保存内容时:
TypeError: argument of type 'function' is not iterable 2011-07-08 13:37:40 ERROR Zope.SiteErrorLog 1310125060.840.103138625259 http://localhost:8081/Plone/++add++my.content.types.curriculum 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 my.content.types.curriculum, line 356, 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 134, in update Module z3c.form.group, line 47, in update Module z3c.form.group, line 43, in updateWidgets Module z3c.form.field, line 275, in update Module z3c.form.browser.multi, line 61, in update Module z3c.form.browser.widget, line 70, in update Module z3c.form.widget, line 396, in update Module z3c.form.widget, line 88, in update Module z3c.form.widget, line 390, in set Module collective.z3cform.datagridfield.datagridfield, line 112, in updateWidgets Module collective.z3cform.datagridfield.datagridfield, line 90, in getWidget Module z3c.form.browser.widget, line 70, in update Module z3c.form.object, line 213, in update Module z3c.form.widget, line 88, in update Module collective.z3cform.datagridfield.datagridfield, line 216, in set Module z3c.form.object, line 229, in applyValue Module z3c.form.validator, line 67, in validate Module zope.schema._bootstrapfields, line 153, in validate Module zope.schema._field, line 325, in _validate TypeError: argument of type 'function' is not iterable
为什么会这样?
I have a custom Dexterity content type with collective.z3c.datagridfield define in the following way:
class ILanguageRow(Interface): # Interface that defines a datagrid row. lang = schema.Choice( title=_(u'Language'), required=True, source=my_languages, default=u'en', ) (...)
This it the function that returns the vocabulary, as in http://plone.org/products/dexterity/documentation/manual/schema-driven-forms/customising-form-behaviour/vocabularies
@grok.provider(IContextSourceBinder) def languages(context): """ Return a vocabulary of language codes and translated language names. """ # z3c.form KSS inline validation hack if not ISiteRoot.providedBy(context): for item in getSite().aq_chain: if ISiteRoot.providedBy(item): context = item # retrieve the localized language names. request = getRequest() portal_state = getMultiAdapter((context, request), name=u'plone_portal_state') lang_items = portal_state.locale().displayNames.languages.items() # build the dictionary return SimpleVocabulary( [SimpleTerm(value=lcode, token=lcode, title=lname)\ for lcode, lname in sorted(lang_items) if lcode in config.CV_LANGS] )
Inside the Edit and Add Form, the Choice field works correctly. But when I attempt to save the content:
TypeError: argument of type 'function' is not iterable 2011-07-08 13:37:40 ERROR Zope.SiteErrorLog 1310125060.840.103138625259 http://localhost:8081/Plone/++add++my.content.types.curriculum 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 my.content.types.curriculum, line 356, 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 134, in update Module z3c.form.group, line 47, in update Module z3c.form.group, line 43, in updateWidgets Module z3c.form.field, line 275, in update Module z3c.form.browser.multi, line 61, in update Module z3c.form.browser.widget, line 70, in update Module z3c.form.widget, line 396, in update Module z3c.form.widget, line 88, in update Module z3c.form.widget, line 390, in set Module collective.z3cform.datagridfield.datagridfield, line 112, in updateWidgets Module collective.z3cform.datagridfield.datagridfield, line 90, in getWidget Module z3c.form.browser.widget, line 70, in update Module z3c.form.object, line 213, in update Module z3c.form.widget, line 88, in update Module collective.z3cform.datagridfield.datagridfield, line 216, in set Module z3c.form.object, line 229, in applyValue Module z3c.form.validator, line 67, in validate Module zope.schema._bootstrapfields, line 153, in validate Module zope.schema._field, line 325, in _validate TypeError: argument of type 'function' is not iterable
Why is this happening?
原文:https://stackoverflow.com/questions/6623921
最满意答案
要访问另一个应用程序域中的对象,它们必须是可序列化的。 虽然您似乎没有在上面的代码中使用IPluginMetadata,但我认为它是针对强类型自定义元数据属性的。 尝试制作Serializable的任何工具。
To access objects in another appdomain they must be serializable. Although you don't seem to be using IPluginMetadata in the code above I assuming it's for a strongly typed custom metadata attribute. Try making whatever implements that Serializable.
相关问答
更多-
MEF CachedAssemblyCatalog - 延迟加载程序集(MEF CachedAssemblyCatalog - Lazy Loading of Assemblies)[2019-07-05]
对于这个@ MEF的论坛有个简短的回答。 我们没有积极维护这个样本,也没有考虑它的稳定性。 希望它对你有用,但我们没有任何更新或进一步开发的计划。 不是我所希望的。 我认为这可能是一个非常有用的功能。 编辑:我已经结束了自己实现这一点,并使其在GitHub上可用 Got a short answer for this @ MEF's forums. We haven't been actively maintaining this sample, and don't consider it stable. ... -
什么是Lazy Loading?(What is Lazy Loading?)[2022-02-12]
这被称为懒惰加载,因为像一个懒惰的人,你正在推迟做一些你不想要的东西。 相反的是Eager Loading,在那里你马上加载东西,很久以前你需要它。 如果您好奇为什么人们可能会使用延迟加载,请考虑采用LOOOOONG时间开始的应用程序。 这个应用程序可能正在做很多热切的加载...从磁盘加载东西,并且在需要之前进行计算和不久之后。 将这与延迟加载进行比较,应用程序将开始更快,但是当您第一次需要执行需要长时间运行的某些操作时,可能会在第一次加载时稍微暂停。 因此,使用延迟加载,您将在运行应用程序的过程中分摊加载 ... -
使用序列化进行深度克隆后,休眠延迟加载异常(hibernate lazy load exception after deep clone using Serialization)[2022-06-09]
自己想出来 而不是使用org.apache.commons.lang3.SerializationUtils.clone()进行深度复制 我使用Dozer Mapper进行深度复制,并且不再有例外。 Figured it out myself instead of deep copy with org.apache.commons.lang3.SerializationUtils.clone() I used Dozer Mapper for deep copy , and there is no exce ... -
如果在实体框架中使用延迟加载,如何序列化实体?(How to serialize entity if using lazy loading in entity framework?)[2023-08-09]
使用延迟加载时,将延迟执行,直到实际需要该属性的值。 您可能遇到错误,因为在访问该属性时已经处理了上下文。 请考虑以下情形: 您有一个名为Country的对象,其中包含一个名为States的延迟加载属性。 您从上下文中获取此对象。 上下文被处理。 你打电话给国家财产。 该物业正在寻找它来自的背景。 抛出错误是因为“已经处理了上下文”。 代码示例: using(var context = new SomeEntityContext()) { var country = context.Countri ... -
toJSON()序列化所有阶段( Node )的属性。 我没有尝试过,但似乎你可以使用setAttr(key,val)将自己的属性添加到舞台上。 在设置它们之后它们将被串行化并且我假设也被反序列化... 请注意,这并不是您要求的,因为额外数据不在JSON的根级别,而是在attrs子对象中 toJSON() serializes all the stage (Node) 's attributes. I didn't try it but it seems like you can add your own ...
-
MEF,延迟加载高级元数据和序列化异常(MEF, Lazy loading with advanced metadata and serialization exception)[2020-01-02]
要访问另一个应用程序域中的对象,它们必须是可序列化的。 虽然您似乎没有在上面的代码中使用IPluginMetadata,但我认为它是针对强类型自定义元数据属性的。 尝试制作Serializable的任何工具。 To access objects in another appdomain they must be serializable. Although you don't seem to be using IPluginMetadata in the code above I assuming it's ... -
防止LAZY关系异常(Prevent LAZY relationship exception)[2023-05-01]
您可以检查初始化是否发生或使用Hibernate.isInitialized和Hibernate.initialize强制初始化。 Solved using string list instead the whole object -
使用会话和延迟加载(working with session and lazy loading)[2022-07-13]
错误在于您的设计。 您正在打开一个会话以获取该对象,并将其保持打开状态。 然后,您打开另一个会话以删除托管对象,但您打算自动关闭此会话。 那你为什么不在FindByID方法中关闭会话呢? 您需要考虑您的设计,因为上述内容不一致 - 或者正如Morten所说,提出更深入的问题(即如何设计)。 由于您需要访问惰性实例,因此您最好使用Morten的方法并使用每个Web请求的会话或通过设置自己的请求上下文(其中包含会话)(如果您没有创建Web应用程序)。 如果您还没有基于上下文的设计,则更简单的方法是在事件开始时创 ... -
奇怪的延迟加载异常(Strange lazy loading exception)[2022-05-01]
任务调度程序直接在服务实现上执行该方法,而不是通过代理,因此它不会在该范围内启动@Transactional并启动Hibernate会话。 尝试创建另一个在WordService中连接并在WordService放置计划的bean,以便在WordService代理上调用该方法。 那应该清除它。 The task scheduler is executing that method directly on the service implementation, not going through the Pro ... -
您在其他问题中引用的无属性方法配置MEF文章包括如何在不使用属性的情况下添加元数据的示例。 该示例显示了PartBuilder.ExportProperties重载的使用,该重载将Action
作为参数并使用ExportBuilder.AddMetadata重载之一来为特定导出添加元数据。 这不是添加元数据的唯一方法。 PartBuilder的所有导出方法都有一个重载,它使用ExportBuilder参数获取Action<> (或Action <,>) ...