implement lookup

This commit is contained in:
j 2015-02-16 16:00:26 +00:00
parent bea4eb7335
commit 7ae02d5678

View file

@ -699,8 +699,21 @@ def lookup(request, data):
} }
see: add, edit, find, get, remove, upload see: add, edit, find, get, remove, upload
''' '''
i = None
if 'id' in data: if 'id' in data:
i = models.Item.objects.get(public_id=data['id']) i = models.Item.objects.get(public_id=data['id'])
elif not filter(None, [d not in ('title', 'year', 'director') for d in data.keys()]):
key = data.keys()[0]
value = data[key]
qs = models.Item.objects.find({'query': {
'conditions': [
{'key': key, 'value': data[key], 'operator': '=='} for key in data
],
'operator': '&'
}}, request.user)
if qs.count() == 1:
i = qs[0]
if i:
r = {'id': i.public_id} r = {'id': i.public_id}
for key in ('title', 'director', 'year'): for key in ('title', 'director', 'year'):
r[key] = i.get(key) r[key] = i.get(key)