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
def do_copy(self, new_ids=False, id_scope=None, id_remap=None): cp = DBChange.do_copy(self, new_ids, id_scope, id_remap) cp.__class__ = ChangeOp return cp
def __init__(self, *args, **kwargs): DBChange.__init__(self, *args, **kwargs)