From 980e68ccc6f5b45ae7e0bd99735ee3d1be6bfd78 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 8 Jan 2016 22:54:46 +0530 Subject: [PATCH] record changes with old timestamp --- oml/changelog.py | 18 ++++++++++++++++++ oml/item/models.py | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/oml/changelog.py b/oml/changelog.py index 45d9f63..fea4f00 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -61,6 +61,22 @@ class Changelog(db.Model): #if state.nodes: # state.nodes.queue('peered', 'pushChanges', [c.json()]) + @classmethod + def record_ts(cls, user, ts, action, *args): + # fixme remove + c = cls() + c.created = datetime.utcnow() + c.timestamp = datetime2ts(ts) + c.user_id = user.id + c.revision = cls.query.filter_by(user_id=user.id).count() + c.data = json.dumps([action] + list(args), ensure_ascii=False) + _data = str(c.revision) + str(c.timestamp) + c.data + _data = _data.encode() + state.db.session.add(c) + state.db.session.commit() + #if state.nodes: + # state.nodes.queue('peered', 'pushChanges', [c.json()]) + @classmethod def apply_changes(cls, user, changes): trigger = changes @@ -144,6 +160,8 @@ class Changelog(db.Model): def action_edititem(self, user, timestamp, itemid, meta): from item.models import Item i = Item.get(itemid) + if itemid == 'RDWQN35QAY6VW2UQEINOTQXLUCOFKIZK': + return True if not i: logger.debug('ignore edititem for unknown item %s %s', timestamp, itemid) return True diff --git a/oml/item/models.py b/oml/item/models.py index 7925f12..8496e95 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -285,7 +285,7 @@ class Item(db.Model): self.save() user = state.user() if record and user in self.users: - Changelog.record(user, 'edititem', self.id, record) + Changelog.record_ts(user, 'edititem', modified, self.id, record) def update_primaryid(self, key=None, id=None, scrape=True, modified=None): if key is None and id is None: @@ -325,7 +325,7 @@ class Item(db.Model): f.move() user = state.user() if user in self.users: - Changelog.record(user, 'edititem', self.id, record) + Changelog.record_ts(user, 'edititem', modified, self.id, record) def edit_metadata(self, data): Scrape.query.filter_by(item_id=self.id).delete()