简体   繁体   中英

Losing some z3c relation data on restart

I have the following code which is meant to programmatically assign relation values to a custom content type.

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

Snippet of schema for custom content type

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

When I run my script everything looks good. The problem is when my template for the custom content tries to call "pub/from_object/absolute_url" the value is blank - only after a restart. Interestingly, I can get other attributes of pub/from_object after a restart, just not it's URL.

from_object retrieves the referencing object from the relation catalog, but doesn't put the object back in its proper Acquisition chain. See http://docs.plone.org/external/plone.app.dexterity/docs/advanced/references.html#back-references for a way to do it that should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM