def _to_commit(self): self['state'] = 'commit' self.sync() for coll in self['new'].values(): for model in coll: model['_trans'].remove(self.id) model.sync() for coll in self['update'].values(): for model in coll: model['_trans'].remove(self.id) model.sync() self['state'] = 'finished' self.sync()
def rollback(self): # delete new documents for coll, models in self["new"]: model_class = mago.types.models[coll] for model in models: model['_trans'].pop(self.id, None) model_class.collection().remove({"_id", model.id}) for models in self['del'].values(): for model in models: model["_trans"].pop(self.id, None) model.sync() # TODO: check it! for models in self['update'].values(): for model in models: model['_trans'].pop(self.id, None) model.sync() self.delete()
def _to_pending(self): self['state'] = 'pending' self.sync() for coll in self['new'].values(): for model in coll: if self.id in model['_trans']: continue model['_trans'].append(self.id) model.save() for coll, ids in self['del'].items(): model_class = mago.types.models[coll] for model_id in ids: # TODO: If it was already remove? model_class.collection().remove({"_id": model_id}) for coll in self['update'].values(): for model in coll: if self.id in model['_trans']: continue model['_trans'].append(self.id) model.sync()