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

时间:2015-11-12 16:09:18

标签: 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))

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

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。

1 个答案:

答案 0 :(得分:6)

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