我有以下代码,旨在以编程方式将关系值分配给自定义内容类型。
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寻找一种可行的方法。
关于plone - 重启时丢失一些 z3c 关系数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33675990/