Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

Forbedret formateringen av strenger i book/person to_string(). #5 #6

This commit is contained in:
Andreas Lindahl Flåten 2011-03-05 20:20:50 +00:00
parent e2dcdc460f
commit 52a9132664
1 changed files with 7 additions and 5 deletions

View File

@ -47,20 +47,22 @@ class Book(models.Model):
#Generate a string from book info
def to_string(self, commit=False):
scratch = ''
authors = ','.join(map(lambda x: str(x),self.get_authors()))
if commit:
# generate commit string by sending self.to_dict to oysteini function
print self.to_dict()
print fileformat.write_action(self.to_dict())
else:
format = '%-15s: %50s \n'
for field in book_fields:
try:
scratch += '%-15s: %50s' % (field[1],eval('self.'+field[0])) + '\n'
scratch += format % (field[1],eval('self.'+field[0]))
except AttributeError:
scratch += '%-15s: %50s' % (field[1], '') + '\n'
scratch += 'Authors'.ljust(15, ' ') + ':'
scratch += authors.rjust(51, ' ')
scratch += format % (field[1], '')
authors = ','.join(map(lambda x: str(x),self.get_authors()))
scratch += format % ('Authors', authors)
# scratch += 'Authors'.ljust(15, ' ') + ':'
# scratch += authors.rjust(51, ' ')
scratch += '\n'
return scratch