コード例 #1
0
def breakRelations(event):
    """Break relations on any object pointing to us.

    That is, store the object path on the broken relation.
    """
    obj = event.object
    if not IHasIncomingRelations.providedBy(obj):
        return
    catalog = component.queryUtility(ICatalog)
    intids = component.queryUtility(IIntIds)
    if catalog is None or intids is None:
        return

    # find all relations that point to us
    try:
        obj_id = intids.getId(obj)
    except KeyError:
        # our intid was unregistered already
        return
    rels = list(catalog.findRelations({'to_id': intids.getId(obj)}))
    for rel in rels:
        rel.broken(rel.to_path)
        # we also need to update the relations for these objects
        notify(ObjectModifiedEvent(rel.from_object))
コード例 #2
0
 def test_relation(self):
     contact = create(Builder('contact'))
     self.assertTrue(IHasIncomingRelations.providedBy(contact))