diff --git a/oml/changelog.py b/oml/changelog.py index 444e7cd..b0356af 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -71,12 +71,13 @@ class Changelog(db.Model): logger.debug('record change: %s', c.json()) @classmethod - def apply_changes(cls, user, changes, first=False): + def apply_changes(cls, user_, changes, first=False): + from user.models import User + user = user_ trigger = changes if trigger: trigger_event('change', {}) if first: - logger.debug('remove left over items') items = set() lists = {} peers = set() @@ -103,12 +104,11 @@ class Changelog(db.Model): qs = user.lists.filter_by(name=name) if qs.count(): l = qs[0] - remove = [] for i in l.get_items(): if i.id not in lists[name]: - remove.append(i.id) - l.items.remove(i.id) - for peer in user.models.Users.query: + if i.id in l.items: + l.items.remove(i.id) + for peer in User.query: if user.id in peer.info.get('users', {}) and peer.id not in peers: del peer.info['users'][user.id] peer.save()