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

Losing some z3c relation data on restart

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

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))

自定义内容类型的架构片段

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

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

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