我有以下代码,用于以编程方式将关系值分配给自定义内容类型.
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.
from_object从关系目录中检索引用对象,但不将对象放回其正确的获取链中.请参阅http://docs.plone.org/external/plone.app.dexterity/docs/advanced/references.html#back-references,了解应该如何运作的方法.
| 归档时间: |
|
| 查看次数: |
61 次 |
| 最近记录: |