重启时丢失一些z3c关系数据

Eso*_*oth 2 plone dexterity

我有以下代码,用于以编程方式将关系值分配给自定义内容类型.

publications = # some data

catalog = getToolByName(context, 'portal_catalog')
for pub in publications:
  if pub['custom_id']:
    results = catalog(custom_id=pub['custom_id'])
    if len(results) == 1:
      obj = results[0].getObject()
      measures = []
      for m in pub['measure']:
        if m in context.objectIds():
          m_id = intids.getId(context[m])
          relation = RelationValue(m_id)
          measures.append(relation)
      obj.measures = measures
      obj.reindexObject()
      notify(ObjectModifiedEvent(obj))
Run Code Online (Sandbox Code Playgroud)

自定义内容类型的模式片段

measures = RelationList(
  title=_(u'Measure(s)'),
  required=False,
  value_type=RelationChoice(title=_(u'Measure'),
                            source=ObjPathSourceBinder(object_provides='foo.bar.interfaces.measure.IMeasure')),
  )
Run Code Online (Sandbox Code Playgroud)

当我运行我的脚本时,一切都很好看.问题是当我的自定义内容模板尝试调用"pub/from_object/absolute_url"时,该值为空 - 仅在重新启动后.有趣的是,我可以在重启后获得pub/from_object的其他属性,而不是它的URL.

Dav*_*ick 6

from_object从关系目录中检索引用对象,但不将对象放回其正确的获取链中.请参阅http://docs.plone.org/external/plone.app.dexterity/docs/advanced/references.html#back-references,了解应该如何运作的方法.

  • 我必须使用Plone 4.1这个项目,它有一个plone.app.relationfield版本,因为它是添加了猴子补丁.你引用的文档提供了一个有效的解决方案,谢谢! (2认同)