From e9e508d1eb2c58d2d9fb8293711e92ea97a17df7 Mon Sep 17 00:00:00 2001 From: almelid Date: Wed, 29 Sep 2010 20:21:52 +0000 Subject: [PATCH] =?UTF-8?q?begynt=20p=C3=A5=20worblehat=20show,=20m=C3=A5?= =?UTF-8?q?=20n=C3=A5=20skrive=20printfunksjoner=20for=20forfattere=20og?= =?UTF-8?q?=20b=C3=B8ker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/worblehat.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/python/worblehat.py b/python/worblehat.py index e08d3fc..12cc566 100755 --- a/python/worblehat.py +++ b/python/worblehat.py @@ -11,7 +11,24 @@ import sys import search def show_book_or_person(ids, commit_format=False, tmp_file=False): - pass + for id in ids: + object = get_book_or_person(id) + print object + +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 def search_book_cmd(search_strings, search_description=False): books = search_book(search_strings, search_description)