use peer.library in some places
This commit is contained in:
parent
647afcf2ab
commit
9a9185d3d5
2 changed files with 15 additions and 2 deletions
|
@ -124,8 +124,15 @@ class Parser(object):
|
||||||
u = self._user.query.filter_by(nickname=nickname).one()
|
u = self._user.query.filter_by(nickname=nickname).one()
|
||||||
else:
|
else:
|
||||||
u = self._user.query.filter_by(id=settings.USER_ID).one()
|
u = self._user.query.filter_by(id=settings.USER_ID).one()
|
||||||
l = self._list.query.filter_by(user_id=u.id, name=name).one()
|
if nickname:
|
||||||
ids = l.get_items().options(load_only('id'))
|
peer = utils.get_peer(u.id)
|
||||||
|
if name:
|
||||||
|
ids = peer.info['lists'].get(name, [])
|
||||||
|
else:
|
||||||
|
ids = list(peer.library.keys())
|
||||||
|
else:
|
||||||
|
l = self._list.query.filter_by(user_id=u.id, name=name).one()
|
||||||
|
ids = l.get_items().options(load_only('id'))
|
||||||
in_op = operators.notin_op if exclude else operators.in_op
|
in_op = operators.notin_op if exclude else operators.in_op
|
||||||
q = in_op(self._model.id, ids)
|
q = in_op(self._model.id, ids)
|
||||||
return q
|
return q
|
||||||
|
|
|
@ -372,6 +372,12 @@ class List(db.Model):
|
||||||
return self.public_id
|
return self.public_id
|
||||||
|
|
||||||
def items_count(self):
|
def items_count(self):
|
||||||
|
if self.user_id != settings.USER_ID:
|
||||||
|
peer = utils.get_peer(self.user_id)
|
||||||
|
if self.name:
|
||||||
|
return len(peer.info['lists'].get(self.name, []))
|
||||||
|
else:
|
||||||
|
return len(peer.library)
|
||||||
return self.get_items().count()
|
return self.get_items().count()
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
|
|
Loading…
Reference in a new issue