dont reuse same variable in loop

This commit is contained in:
j 2016-02-23 09:43:33 +05:30
parent fba3f46787
commit 314bb863eb

View file

@ -247,17 +247,18 @@ def findMetadata(data):
elif key == 'id':
import user.models
items = {}
value = data[key]
for u in user.models.User.query.filter_by(peered=True):
peer = utils.get_peer(u.id)
if data[key] in peer.library:
h = peer.get_metahash(data[key])
if value in peer.library:
h = peer.get_metahash(value)
if h not in items:
items[h] = peer.library[data[key]].get('meta', {}).copy()
items[h] = peer.library[value].get('meta', {}).copy()
items[h]['users'] = [u.id]
j = items[h]
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in j and not isinstance(j[key], list):
j[key] = [j[key]] if j[key] else []
for key_ in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key_ in j and not isinstance(j[key_], list):
j[key_] = [j[key_]] if j[key_] else []
else:
items[h]['users'].append(u.id)
response['items'] = list(items.values())