Exemple #1
0
def create_delete_op_chain(object, parent=(None, None)):
    opChain = []
    for (obj, parentType, parentId) in object.db_children(parent):
        op = DBDelete(
            id=-1,
            what=obj.vtType,
            objectId=obj.db_id,
            parentObjType=parentType,
            parentObjId=parentId,
        )
        opChain.append(op)
    return opChain
Exemple #2
0
def create_change_op_chain(old_obj, new_obj, parent=(None, None)):
    opChain = []
    new_obj = copy.copy(new_obj)
    deletes = old_obj.db_children(parent)
    deletes.pop()
    for (obj, parentType, parentId) in deletes:
        op = DBDelete(
            id=-1,
            what=obj.vtType,
            objectId=obj.db_id,
            parentObjType=parentType,
            parentObjId=parentId,
        )
        opChain.append(op)

    adds = new_obj.db_children(parent, True)
    (obj, parentType, parentId) = adds.pop()
    op = DBChange(
        id=-1,
        what=obj.vtType,
        oldObjId=old_obj.db_id,
        newObjId=obj.db_id,
        parentObjType=parentType,
        parentObjId=parentId,
        data=new_obj,
    )
    opChain.append(op)

    adds.reverse()
    for (obj, parentType, parentId) in adds:
        op = DBAdd(
            id=-1,
            what=obj.vtType,
            objectId=obj.db_id,
            parentObjType=parentType,
            parentObjId=parentId,
            data=obj,
        )
    return opChain