From df5c6c5a889f5b4897f06052a1e1f8ab963b9b1c Mon Sep 17 00:00:00 2001 From: oysteini Date: Sun, 6 Mar 2011 12:21:50 +0000 Subject: [PATCH] =?UTF-8?q?Endret=20litt=20p=C3=A5=20show-kommandoen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/worblehat.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/python/worblehat.py b/python/worblehat.py index e56800e..d829a95 100755 --- a/python/worblehat.py +++ b/python/worblehat.py @@ -4,20 +4,34 @@ import os os.environ['DJANGO_SETTINGS_MODULE']='web.settings' from web.library.models import * +from web.library.fileformat import read_actionlist, write_actionlist from django.db.models import Q from util import * import getopt import sys +import types import search import placement def show_book_or_person(ids, commit_format=False, tmp_file=False): - for id in ids: - object = get_book_or_person(id) - if object: - print object.to_string() + objects = map(get_book_or_person, ids) + for i in range(len(ids)): + if not objects[i]: + objects[i] = 'No book or person with id %s.' % id + elif commit_format: + objects[i] = objects[i].to_dict() else: - print 'No book or person with id %s.' % id + objects[i] = objects[i].to_string() + if commit_format: + output = write_actionlist(objects) + else: + output = '\n'.join(objects) + if tmp_file: + # TODO + #return write_tmpfile('-'.join(ids), output) + pass + else: + print output def get_book_or_person(id): books = Book.objects.filter(Q(isbn=id)|Q(id__id=id)).all()