From bbccea9ad8477ed8e811dc1b3fb8a678f089fbb1 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sun, 6 Mar 2011 19:31:02 +0000 Subject: [PATCH] =?UTF-8?q?Forandret=20p=C3=A5=20hvordan=20outputen=20fra?= =?UTF-8?q?=20'show'-kommandoen=20ser=20ut.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/web/library/models.py | 61 ++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/python/web/library/models.py b/python/web/library/models.py index fd4db02..c2c5c5f 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -52,16 +52,30 @@ class Book(models.Model): print fileformat.write_action(self.to_dict()) else: - format = '%-15s: %50s \n' - for field in book_fields: - try: - scratch += format % (field[1],eval('self.'+field[0])) - except Id.DoesNotExist: - scratch += format % (field[1], "None") - except AttributeError: - scratch += format % (field[1], '') - authors = ', '.join(map(unicode, self.get_authors())) - scratch += format % ('Authors', authors) + if self.getid(): + scratch = 'book %s %s\n' % (self.isbn, self.getid()) + else: + scratch = 'book %s\n' % self.isbn + scratch += 'Title: %s\n' % self.title + if self.subtitle: + scratch += 'Subtitle: %s\n' % self.subtitle + scratch += 'ISBN: %s\n' % self.isbn + scratch += 'Persons:\n' + for bp in self.persons.all(): + scratch += ' %s %s %s (%s)\n' % (bp.person.id, + bp.person.first_name, bp.person.last_name, + bp.relation) + if len(self.persons.all()) == 0: + scratch += ' (no persons associated with this book)\n' + if self.series: scratch += 'Part of series: %s %s\n' % (self.series.id, self.series.title) + scratch += 'Category: %s\n' % self.category.id + if self.publisher: scratch += 'Publisher: %s\n' % self.publisher + if self.published_year: scratch += 'Published year: %s\n' % self.published_year + if self.edition: scratch += 'Edition: %s\n' % self.edition + if self.num_pages: scratch += 'Number of pages: %s\n' % self.num_pages + if self.description: + scratch += 'Description:\n%s\n' % '\n'.join(map(lambda line: ' '+line, + self.description.split('\n'))) return scratch @@ -105,13 +119,19 @@ class Book(models.Model): def getid(self): - if self.id: - return self.id.id + try: + if self.id: + return self.id.id + except Id.DoesNotExist: + pass return None def setid(self,newid): - if self.id: - self.id.delete() + try: + if self.id: + self.id.delete() + except Id.DoesNotExist: + pass newid = Id(book=self,id=newid) newid.save() @@ -177,12 +197,13 @@ class Person(models.Model): #generate commit-string print fileformat.write_action(self.to_dict()) else: - format = '%-10s: %50s \n' - scratch = format % ('Name', ' '.join((self.first_name, self.last_name))) - scratch += format % ('ID', self.id) - - books = ', '.join(map(lambda x: x.book.title, self.books.all())) - scratch += format % ('Books', books) + scratch = 'person %s\n' % self.id + scratch += 'Name: %s %s\n' % (self.first_name, self.last_name) + scratch += 'Books:\n' + for bp in self.books.all(): + scratch += ' %s %s (%s)\n' % (bp.book.isbn, bp.book.title, bp.relation.name) + if len(self.books.all()) == 0: + scratch += ' (no books associated with this person)\n' return scratch