Forandret på hvordan outputen fra 'show'-kommandoen ser ut.
This commit is contained in:
parent
be4f746274
commit
bbccea9ad8
|
@ -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):
|
||||
try:
|
||||
if self.id:
|
||||
return self.id.id
|
||||
except Id.DoesNotExist:
|
||||
pass
|
||||
return None
|
||||
|
||||
def setid(self,newid):
|
||||
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
|
||||
|
||||
|
|
Reference in New Issue