Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

slang inn en liten fil med en rudimentær boksøkefunksjon

This commit is contained in:
Øyvind Almelid 2010-09-27 15:08:23 +00:00
parent 210051c407
commit b7e059626d
2 changed files with 22 additions and 1 deletions

View File

@ -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

21
python/search.py Normal file
View File

@ -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()