Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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()