changelog timestamp
This commit is contained in:
parent
4d1d96c07c
commit
8b77c634f3
1 changed files with 6 additions and 5 deletions
|
@ -7,7 +7,7 @@ import logging
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from utils import valid
|
from utils import valid, datetime2ts, ts2datetime
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from settings import db
|
from settings import db
|
||||||
|
@ -46,7 +46,7 @@ class Changelog(db.Model):
|
||||||
def record(cls, user, action, *args):
|
def record(cls, user, action, *args):
|
||||||
c = cls()
|
c = cls()
|
||||||
c.created = datetime.utcnow()
|
c.created = datetime.utcnow()
|
||||||
c.timestamp = int(c.created.strftime('%s'))
|
c.timestamp = datetime2ts(c.created)
|
||||||
c.user_id = user.id
|
c.user_id = user.id
|
||||||
c.revision = cls.query.filter_by(user_id=user.id).count()
|
c.revision = cls.query.filter_by(user_id=user.id).count()
|
||||||
c.data = json.dumps([action] + list(args))
|
c.data = json.dumps([action] + list(args))
|
||||||
|
@ -117,7 +117,7 @@ class Changelog(db.Model):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
timestamp = self.timestamp or self.created.strftime('%s')
|
timestamp = self.timestamp or datetime2ts(self.created)
|
||||||
return [self.revision, timestamp, self.sig, self.data]
|
return [self.revision, timestamp, self.sig, self.data]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -149,7 +149,7 @@ class Changelog(db.Model):
|
||||||
return True
|
return True
|
||||||
if not i:
|
if not i:
|
||||||
i = Item.get_or_create(itemid, info)
|
i = Item.get_or_create(itemid, info)
|
||||||
i.modified = datetime.utcfromtimestamp(float(timestamp))
|
i.modified = ts2datetime(timestamp)
|
||||||
if user not in i.users:
|
if user not in i.users:
|
||||||
i.users.append(user)
|
i.users.append(user)
|
||||||
i.update()
|
i.update()
|
||||||
|
@ -159,6 +159,7 @@ class Changelog(db.Model):
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
i = Item.get(itemid)
|
i = Item.get(itemid)
|
||||||
if i.timestamp > timestamp:
|
if i.timestamp > timestamp:
|
||||||
|
logger.debug('ignore edititem change %s %s %s', timestamp, itemid, meta)
|
||||||
return True
|
return True
|
||||||
keys = filter(lambda k: k in Item.id_keys, meta.keys())
|
keys = filter(lambda k: k in Item.id_keys, meta.keys())
|
||||||
if keys:
|
if keys:
|
||||||
|
@ -171,7 +172,7 @@ class Changelog(db.Model):
|
||||||
i.update_mainid(key, meta[key])
|
i.update_mainid(key, meta[key])
|
||||||
else:
|
else:
|
||||||
i.update_meta(meta)
|
i.update_meta(meta)
|
||||||
i.modified = datetime.utffromtimestamp(float(timestamp))
|
i.modified = ts2datetime(timestamp)
|
||||||
i.save()
|
i.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue