forked from 0x2620/pandora
implement lookup
This commit is contained in:
parent
bea4eb7335
commit
7ae02d5678
1 changed files with 13 additions and 0 deletions
|
@ -699,8 +699,21 @@ def lookup(request, data):
|
|||
}
|
||||
see: add, edit, find, get, remove, upload
|
||||
'''
|
||||
i = None
|
||||
if 'id' in data:
|
||||
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}
|
||||
for key in ('title', 'director', 'year'):
|
||||
r[key] = i.get(key)
|
||||
|
|
Loading…
Reference in a new issue