From b7e059626dc09ee68533a9a2c532fd9215d47138 Mon Sep 17 00:00:00 2001 From: almelid Date: Mon, 27 Sep 2010 15:08:23 +0000 Subject: [PATCH] =?UTF-8?q?slang=20inn=20en=20liten=20fil=20med=20en=20rud?= =?UTF-8?q?iment=C3=A6r=20boks=C3=B8kefunksjon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/google_interface.py | 2 +- python/search.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 python/search.py diff --git a/python/google_interface.py b/python/google_interface.py index d2d2652..bab177a 100644 --- a/python/google_interface.py +++ b/python/google_interface.py @@ -122,7 +122,7 @@ def select_from_list(list, attributes=False, item_name=""): answer = raw_input(str("Found one %s: %s. Use this? [y]/n> " %(item_name,' '.join([eval("list[0]."+attribute) for attribute in attributes])))) else: answer = raw_input(str("Found one %s: %s. Use this? [y]/n> " %(item_name,list[0]))) - if answer in ['yes', 'y']: + if answer in ['yes', 'y', '']: return list[0] else: return None diff --git a/python/search.py b/python/search.py new file mode 100644 index 0000000..95c1613 --- /dev/null +++ b/python/search.py @@ -0,0 +1,21 @@ +import os +os.environ['DJANGO_SETTINGS_MODULE']='web.settings' +from web.library.models import * +from django.db.models import Q + +def search(string): + words = string.split() + basic_query = Book.objects + for word in words: + basic_query=basic_query.filter(Q(title__icontains=word) | + Q(subtitle__icontains=word) | + Q(id__id__icontains=word) | + Q(person__person__first_name__icontains=word) | + Q(person__person__last_name__icontains=word)) + return remove_duplicates(basic_query.all()) + +def remove_duplicates(list): + d = {} + for i in list: + d[i]=None + return d.keys()