Plone / IRelatedItems. How can I programmatically set related elements such as agility content?

In the case of IAfterTransitionEvent, I try to capture a public object event and when the object is published, two objects are created and I want to link them.

In the xml file type of the object that is being published, I added to the behavior:

element value="plone.app.relationfield.behavior.IRelatedItems"

So that I can get related items.

In my event function, I have:

@grok.subscribe(InitialContract, IAfterTransitionEvent)
def itemPublished(obj, event):
    site = api.portal.get()
    if event.status['action'] == 'publish':

        house_agreement = customCreateFunction(container...,type..)
        #I get the HouseAgreement object
        labor_contract = customCreateFunction(container....,type)
        #I get the LaborContract object
        relIDs = []
        relIDs.append(RelationValue(IUUID(house_agreement)))
        relIDs.append(RelationValue(IUUID(labor_contract)))

        obj.relatedItems = relIDs

Unfortunately, printing obj.relatedItems gives me an empty list, and when I go to the View class and browse under the category, the Related Items field is empty. I tried _relatedItems instead of relatedItems, but this does not seem to work, as I think it creates an attribute for obj. I also tried using IUUID instead of converting it to RelationValue, but that does not give me any error at all.

, relatedItems, , , .

, ?

, , .

+4
1

RelationValues.

>>> from zope.component import getUtility
>>> from zope.intid.interfaces import IIntIds
>>> from z3c.relationfield import RelationValue


>>> intids = getUtility(IIntIds)
>>> source.relatedItems = [RelationValue(self.intids.getId(target))]
>>> source.relatedItems
[<z3c.relationfield.relation.RelationValue object at 0x10bf2eed8>]

...

>>> target_ref = source.relatedItems[0]
>>> target_ref.to_object
<XXX at / Plone/target>

:

  • RelationValues ​​ Intid not uuid.
+5

All Articles