use timestamp from changelog

This commit is contained in:
j 2016-01-08 22:43:33 +05:30
parent 54636fbc63
commit 9cf8417c30
2 changed files with 12 additions and 10 deletions

View file

@ -159,18 +159,16 @@ class Changelog(db.Model):
if keys:
key = keys[0]
primary = [key, meta[key]]
i.modified = ts2datetime(timestamp)
if primary:
if not meta[key] and i.meta.get('primaryid', [''])[0] == key:
logger.debug('remove id mapping %s %s', i.id, primary)
i.update_primaryid(*primary, scrape=False)
i.modified = ts2datetime(timestamp)
i.update_primaryid(*primary, scrape=False, modified=i.modified)
elif meta[key] and i.meta.get('primaryid') != primary:
logger.debug('edit mapping %s %s', i.id, primary)
i.update_primaryid(*primary, scrape=False)
i.modified = ts2datetime(timestamp)
i.update_primaryid(*primary, scrape=False, modified=i.modified)
else:
i.update_meta(meta)
i.modified = ts2datetime(timestamp)
i.update_meta(meta, modified=i.modified)
i.save()
user.clear_smart_list_cache()
return True

View file

@ -264,7 +264,7 @@ class Item(db.Model):
'title'
)
def update_meta(self, data):
def update_meta(self, data, modified=None):
update = False
record = {}
for key in self.meta_keys:
@ -279,13 +279,15 @@ class Item(db.Model):
update = True
if update:
self.update()
self.modified = datetime.utcnow()
if not modified:
modified = datetime.utcnow()
self.modified = modified
self.save()
user = state.user()
if record and user in self.users:
Changelog.record(user, 'edititem', self.id, record)
def update_primaryid(self, key=None, id=None, scrape=True):
def update_primaryid(self, key=None, id=None, scrape=True, modified=None):
if key is None and id is None:
if 'primaryid' not in self.meta:
return
@ -313,7 +315,9 @@ class Item(db.Model):
if scrape:
self.scrape()
self.update_icons()
self.modified = datetime.utcnow()
if not modified:
modified = datetime.utcnow()
self.modified = modified
self.save()
#if not scrape:
# Scrape.get_or_create(self.id)