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

Fikset litt på show-kommandoen.

Nå kan man slå opp bøker etter id også, ikke bare isbn.  Dessuten får
man en fornuftig feilmelding hvis man prøver å vise noe som ikke
eksisterer.
This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-03-06 11:21:44 +00:00
parent 8a578ffdb2
commit 39c3e4ec38
1 changed files with 14 additions and 16 deletions

View File

@ -13,24 +13,22 @@ import placement
def show_book_or_person(ids, commit_format=False, tmp_file=False):
for id in ids:
object = get_book_or_person(id)
# TODO: skriv ut mer informasjon
print object.to_string()
object = get_book_or_person(id)
if object:
print object.to_string()
else:
print 'No book or person with id %s.' % id
def get_book_or_person(id):
if id.isdigit():
return get_in_order([Book,Person],id)
else:
return get_in_order([Person,Book],id)
def get_in_order(list, id):
for object in list:
try:
b = object.objects.get(pk=id)
return b
except object.DoesNotExist:
pass
return None
books = Book.objects.filter(Q(isbn=id)|Q(id__id=id)).all()
persons = Person.objects.filter(id=id)
if len(books) + len(persons) > 1:
print 'Warning: More than one match for id %d.' % id
print 'This should not happen.'
if len(books) > 0:
return books[0]
if len(persons) > 0:
return persons[0]
def remove_duplicates(list):
d = {}