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())
|
print fileformat.write_action(self.to_dict())
|
||||||
|
|
||||||
else:
|
else:
|
||||||
format = '%-15s: %50s \n'
|
if self.getid():
|
||||||
for field in book_fields:
|
scratch = 'book %s %s\n' % (self.isbn, self.getid())
|
||||||
try:
|
else:
|
||||||
scratch += format % (field[1],eval('self.'+field[0]))
|
scratch = 'book %s\n' % self.isbn
|
||||||
except Id.DoesNotExist:
|
scratch += 'Title: %s\n' % self.title
|
||||||
scratch += format % (field[1], "None")
|
if self.subtitle:
|
||||||
except AttributeError:
|
scratch += 'Subtitle: %s\n' % self.subtitle
|
||||||
scratch += format % (field[1], '')
|
scratch += 'ISBN: %s\n' % self.isbn
|
||||||
authors = ', '.join(map(unicode, self.get_authors()))
|
scratch += 'Persons:\n'
|
||||||
scratch += format % ('Authors', authors)
|
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
|
return scratch
|
||||||
|
|
||||||
|
@ -105,13 +119,19 @@ class Book(models.Model):
|
||||||
|
|
||||||
|
|
||||||
def getid(self):
|
def getid(self):
|
||||||
|
try:
|
||||||
if self.id:
|
if self.id:
|
||||||
return self.id.id
|
return self.id.id
|
||||||
|
except Id.DoesNotExist:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def setid(self,newid):
|
def setid(self,newid):
|
||||||
|
try:
|
||||||
if self.id:
|
if self.id:
|
||||||
self.id.delete()
|
self.id.delete()
|
||||||
|
except Id.DoesNotExist:
|
||||||
|
pass
|
||||||
newid = Id(book=self,id=newid)
|
newid = Id(book=self,id=newid)
|
||||||
newid.save()
|
newid.save()
|
||||||
|
|
||||||
|
@ -177,12 +197,13 @@ class Person(models.Model):
|
||||||
#generate commit-string
|
#generate commit-string
|
||||||
print fileformat.write_action(self.to_dict())
|
print fileformat.write_action(self.to_dict())
|
||||||
else:
|
else:
|
||||||
format = '%-10s: %50s \n'
|
scratch = 'person %s\n' % self.id
|
||||||
scratch = format % ('Name', ' '.join((self.first_name, self.last_name)))
|
scratch += 'Name: %s %s\n' % (self.first_name, self.last_name)
|
||||||
scratch += format % ('ID', self.id)
|
scratch += 'Books:\n'
|
||||||
|
for bp in self.books.all():
|
||||||
books = ', '.join(map(lambda x: x.book.title, self.books.all()))
|
scratch += ' %s %s (%s)\n' % (bp.book.isbn, bp.book.title, bp.relation.name)
|
||||||
scratch += format % ('Books', books)
|
if len(self.books.all()) == 0:
|
||||||
|
scratch += ' (no books associated with this person)\n'
|
||||||
|
|
||||||
return scratch
|
return scratch
|
||||||
|
|
||||||
|
|
Reference in New Issue