diff --git a/oml/changelog.py b/oml/changelog.py index d12c8b3..482501e 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -50,9 +50,16 @@ class Changelog(db.Model): if '_commit' in kwargs: commit = kwargs['_commit'] del kwargs['_commit'] + if '_ts' in kwargs: + timestamp = kwargs['_ts'] + del kwargs['_ts'] + else: + timestamp = None c = cls() c.created = datetime.utcnow() - c.timestamp = datetime2ts(c.created) + if not timestamp: + timestamp = c.created + c.timestamp = datetime2ts(timestamp) 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) @@ -63,24 +70,6 @@ class Changelog(db.Model): state.db.session.commit() logger.debug('record change: %s', c.json()) - @classmethod - def record_ts(cls, user, ts, action, *args): - # fixme remove - c = cls() - c.created = datetime.utcnow() - if ts: - c.timestamp = datetime2ts(ts) - else: - c.timestamp = datetime2ts(c.created) - 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() - logger.debug('record change: %s', c.json()) - @classmethod def apply_changes(cls, user, changes, first=False): trigger = changes diff --git a/oml/item/models.py b/oml/item/models.py index 3c7ec22..3d72f9b 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -308,7 +308,7 @@ class Item(db.Model): self.update_cover() user = state.user() if record and user in self.users: - Changelog.record_ts(user, modified, 'edititem', self.id, record) + Changelog.record(user, 'edititem', self.id, record, _ts=modified) if 'sharemetadata' in record and not record['sharemetadata']: self.sync_metadata() @@ -356,7 +356,7 @@ class Item(db.Model): self.save() user = state.user() if record and user in self.users: - Changelog.record_ts(user, self.modified, 'edititem', self.id, record) + Changelog.record(user, 'edititem', self.id, record, _ts=self.modified) if 'cover' in record: self.update_cover()