From 7ae02d567870cfe20480a57001d852eacc354bff Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 16 Feb 2015 16:00:26 +0000 Subject: [PATCH] implement lookup --- pandora/item/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandora/item/views.py b/pandora/item/views.py index 2c711f41..a7b9d55c 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -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)