except AttributeError: log.info("Couldn't create {2} revision for {0}:{1}".format( self.table_name, self.record_id, self.command)) log.info("Delta is {0}".format(self.delta)) log.info("Thread is: {0}".format(obj.thread_id)) raise object_public_id = getattr(obj, 'public_id', None) if object_public_id is not None: self.object_public_id = object_public_id def take_snapshot(self, obj): """Record the API's representation of `obj` at the time this transaction is generated, as well as any other properties we want to have available in the transaction log. Used for delta syncing and the ping API.""" from inbox.api.kellogs import encode self.public_snapshot = encode(obj) from inbox.models.message import Message if isinstance(obj, Message): # hack self.private_snapshot = { 'recentdate': obj.thread.recentdate, 'subjectdate': obj.thread.subjectdate, 'filenames': [part.block.filename for part in obj.parts if part.is_attachment]} Index('namespace_id_deleted_at', Transaction.namespace_id, Transaction.deleted_at) HasRevisions = gen_rev_role(Transaction)
@as_declarative() class Base(object): id = Column(Integer, primary_key=True, autoincrement=True) @declared_attr def __tablename__(cls): return cls.__name__.lower() class MonkeyRevision(Base, Revision): public_snapshot = Column(BigJSON) def take_snapshot(self, obj): self.public_snapshot = {'favorite_food': obj.favorite_food} HasRevisions = gen_rev_role(MonkeyRevision) class Monkey(Base, HasRevisions): type = Column(Enum('chimpanzee', 'gorilla', 'rhesus'), nullable=False) name = Column(String(40), nullable=True) age = Column(Integer, nullable=False) @property def favorite_food(self): return 'banana' class Tree(Base): type = Column(Enum('maple', 'palm', 'fir'), nullable=False) location = Column(String(40), nullable=False)