only add items to list once they are available
This commit is contained in:
parent
10e651067c
commit
83ceb5b63f
3 changed files with 25 additions and 18 deletions
|
@ -533,6 +533,9 @@ class Item(db.Model):
|
||||||
self.added = datetime.utcnow()
|
self.added = datetime.utcnow()
|
||||||
Changelog.record(u, 'additem', self.id, f.info)
|
Changelog.record(u, 'additem', self.id, f.info)
|
||||||
Changelog.record(u, 'edititem', self.id, self.meta)
|
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()
|
self.update()
|
||||||
f.move()
|
f.move()
|
||||||
self.update_icons()
|
self.update_icons()
|
||||||
|
|
|
@ -98,9 +98,9 @@ class Peer(object):
|
||||||
elif action == 'editlist':
|
elif action == 'editlist':
|
||||||
name, new = args
|
name, new = args
|
||||||
if name in self.info['lists']:
|
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:
|
else:
|
||||||
self.info['lists'][new] = []
|
self.info['lists'][new['name']] = []
|
||||||
elif action == 'orderlists':
|
elif action == 'orderlists':
|
||||||
self.info['listorder'] = args[0]
|
self.info['listorder'] = args[0]
|
||||||
elif action == 'removelist':
|
elif action == 'removelist':
|
||||||
|
@ -183,15 +183,6 @@ class Peer(object):
|
||||||
os.unlink(self._infopath)
|
os.unlink(self._infopath)
|
||||||
|
|
||||||
def sync_db(self):
|
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 item.models
|
||||||
import user.models
|
import user.models
|
||||||
c_user_id = item.models.user_items.columns['user_id']
|
c_user_id = item.models.user_items.columns['user_id']
|
||||||
|
@ -303,6 +294,15 @@ class Peer(object):
|
||||||
if state.shutdown:
|
if state.shutdown:
|
||||||
break
|
break
|
||||||
state.db.session.commit()
|
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():
|
def sync_db():
|
||||||
from sqlalchemy.orm import load_only
|
from sqlalchemy.orm import load_only
|
||||||
|
|
|
@ -329,18 +329,22 @@ class List(db.Model):
|
||||||
|
|
||||||
def add_items(self, items, commit=True):
|
def add_items(self, items, commit=True):
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
|
available_items = []
|
||||||
for item_id in items:
|
for item_id in items:
|
||||||
i = Item.get(item_id)
|
i = Item.get(item_id)
|
||||||
if i and i not in self.items:
|
if i:
|
||||||
self.items.append(i)
|
if i not in self.items:
|
||||||
if self.user_id == settings.USER_ID:
|
self.items.append(i)
|
||||||
i.queue_download()
|
if self.user_id == settings.USER_ID:
|
||||||
i.update(commit=commit)
|
i.queue_download()
|
||||||
|
i.update(commit=commit)
|
||||||
|
if i.info['mediastate'] == 'available':
|
||||||
|
available_items.append(item_id)
|
||||||
state.db.session.add(self)
|
state.db.session.add(self)
|
||||||
if commit:
|
if commit:
|
||||||
state.db.session.commit()
|
state.db.session.commit()
|
||||||
if self.user_id == settings.USER_ID and self.name != '':
|
if self.user_id == settings.USER_ID and self.name != '' and available_items:
|
||||||
Changelog.record(self.user, 'addlistitems', self.name, items)
|
Changelog.record(self.user, 'addlistitems', self.name, available_items)
|
||||||
|
|
||||||
def get_items(self):
|
def get_items(self):
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
|
|
Loading…
Reference in a new issue