only add items to list once they are available

This commit is contained in:
j 2016-02-11 22:52:39 +05:30
parent 10e651067c
commit 83ceb5b63f
3 changed files with 25 additions and 18 deletions

View file

@ -533,6 +533,9 @@ class Item(db.Model):
self.added = datetime.utcnow()
Changelog.record(u, 'additem', self.id, f.info)
Changelog.record(u, 'edititem', self.id, self.meta)
for l in self.lists.filter_by(user_id=settings.USER_ID):
if l.name != '':
Changelog.record(l.user, 'addlistitems', l.name, [self.id])
self.update()
f.move()
self.update_icons()

View file

@ -98,9 +98,9 @@ class Peer(object):
elif action == 'editlist':
name, new = args
if name in self.info['lists']:
self.info['lists'][new] = self.info['lists'].pop(name)
self.info['lists'][new['name']] = self.info['lists'].pop(name)
else:
self.info['lists'][new] = []
self.info['lists'][new['name']] = []
elif action == 'orderlists':
self.info['listorder'] = args[0]
elif action == 'removelist':
@ -183,15 +183,6 @@ class Peer(object):
os.unlink(self._infopath)
def sync_db(self):
ids = set(self.library.keys())
changed = False
for name, l in self.info.get('lists', {}).items():
removed = set(l) - ids
if removed:
self.info['lists'][name] = list(set(l) - removed)
changed = True
if changed:
self.sync_info()
import item.models
import user.models
c_user_id = item.models.user_items.columns['user_id']
@ -303,6 +294,15 @@ class Peer(object):
if state.shutdown:
break
state.db.session.commit()
ids = set(self.library.keys())
changed = False
for name, l in self.info.get('lists', {}).items():
removed = set(l) - ids
if removed:
self.info['lists'][name] = list(set(l) - removed)
changed = True
if changed:
self.sync_info()
def sync_db():
from sqlalchemy.orm import load_only

View file

@ -329,18 +329,22 @@ class List(db.Model):
def add_items(self, items, commit=True):
from item.models import Item
available_items = []
for item_id in items:
i = Item.get(item_id)
if i and i not in self.items:
if i:
if i not in self.items:
self.items.append(i)
if self.user_id == settings.USER_ID:
i.queue_download()
i.update(commit=commit)
if i.info['mediastate'] == 'available':
available_items.append(item_id)
state.db.session.add(self)
if commit:
state.db.session.commit()
if self.user_id == settings.USER_ID and self.name != '':
Changelog.record(self.user, 'addlistitems', self.name, items)
if self.user_id == settings.USER_ID and self.name != '' and available_items:
Changelog.record(self.user, 'addlistitems', self.name, available_items)
def get_items(self):
from item.models import Item