def merge(self, message=""): if len(self.operations) == 0: raise NothingToMergeError("no operation to merge") with prefix_collections(self.get_collection_name(), System, Node): cloned_system = System.objects.get(name=self.system.name) if self.system.last_transaction != cloned_system.last_transaction: raise MustUpdateError("modification have been merge with the master, please update") transaction = Transaction(self.system, self.operations, message) transaction.save() if self.system.last_transaction is None: to_apply = Transaction.objects(system=self.system).order_by("_id") else: to_apply = Transaction.objects(system=self.system, id__gt=self.system.last_transaction.id).order_by("_id") if len(to_apply) != 1: return #FIXME to_apply[0].apply(self.system) to_apply[0].apply(cloned_system, self.get_collection_name()) self.operations = [] self.save()