diff --git a/oml/changelog.py b/oml/changelog.py index 78a7eda..45d9f63 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -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 diff --git a/oml/item/models.py b/oml/item/models.py index 5ca2c5c..7925f12 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -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)