首页 \ 问答 \ 词汇源,函数不可迭代,在Plone 4.1中具有灵巧性(Vocabulary source, function is not iterable, with dexterity in Plone 4.1)

词汇源,函数不可迭代,在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',
    )

(...)

这就是返回词汇表的功能,如http://plone.org/products/dexterity/documentation/manual/schema-driven-forms/customising-form-b​​ehaviour/vocabularyies

@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
更新时间:2022-03-10 11:03

最满意答案

要访问另一个应用程序域中的对象,它们必须是可序列化的。 虽然您似乎没有在上面的代码中使用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的论坛有个简短的回答。 我们没有积极维护这个样本,也没有考虑它的稳定性。 希望它对你有用,但我们没有任何更新或进一步开发的计划。 不是我所希望的。 我认为这可能是一个非常有用的功能。 编辑:我已经结束了自己实现这一点,并使其在GitHub上可用 Got a short answer for this @ MEF's forums. We haven't been actively maintaining this sample, and don't consider it stable. ...
  • 这被称为懒惰加载,因为像一个懒惰的人,你正在推迟做一些你不想要的东西。 相反的是Eager Loading,在那里你马上加载东西,很久以前你需要它。 如果您好奇为什么人们可能会使用延迟加载,请考虑采用LOOOOONG时间开始的应用程序。 这个应用程序可能正在做很多热切的加载...从磁盘加载东西,并且在需要之前进行计算和不久之后。 将这与延迟加载进行比较,应用程序将开始更快,但是当您第一次需要执行需要长时间运行的某些操作时,可能会在第一次加载时稍微暂停。 因此,使用延迟加载,您将在运行应用程序的过程中分摊加载 ...
  • 自己想出来 而不是使用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 ...
  • 使用延迟加载时,将延迟执行,直到实际需要该属性的值。 您可能遇到错误,因为在访问该属性时已经处理了上下文。 请考虑以下情形: 您有一个名为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 ...
  • 要访问另一个应用程序域中的对象,它们必须是可序列化的。 虽然您似乎没有在上面的代码中使用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 ...
  • 您可以检查初始化是否发生或使用Hibernate.isInitialized和Hibernate.initialize强制初始化。 Solved using string list instead the whole object
  • 错误在于您的设计。 您正在打开一个会话以获取该对象,并将其保持打开状态。 然后,您打开另一个会话以删除托管对象,但您打算自动关闭此会话。 那你为什么不在FindByID方法中关闭会话呢? 您需要考虑您的设计,因为上述内容不一致 - 或者正如Morten所说,提出更深入的问题(即如何设计)。 由于您需要访问惰性实例,因此您最好使用Morten的方法并使用每个Web请求的会话或通过设置自己的请求上下文(其中包含会话)(如果您没有创建Web应用程序)。 如果您还没有基于上下文的设计,则更简单的方法是在事件开始时创 ...
  • 任务调度程序直接在服务实现上执行该方法,而不是通过代理,因此它不会在该范围内启动@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 <,>) ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。