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

La til to_string og to_dict for Person. #5

This commit is contained in:
Andreas Lindahl Flåten 2011-03-05 18:54:58 +00:00
parent 6d22c04847
commit 223864c2ae
3 changed files with 22 additions and 10 deletions

View File

@ -8,7 +8,7 @@ def search_book_cmd(search_strings, search_description=False):
books = search_book(search_strings, search_description) books = search_book(search_strings, search_description)
format = '%-13s %-10s %-40s %-30s' format = '%-13s %-10s %-40s %-30s'
for book in books: for book in books:
print book.to_string(True) print book.to_string(False)
#b_id = book.getid() or '' #b_id = book.getid() or ''
#title = cut_str(book.title, 40, '*') #title = cut_str(book.title, 40, '*')
#authors = map(lambda p: p.first_name+' '+p.last_name, #authors = map(lambda p: p.first_name+' '+p.last_name,

View File

@ -160,14 +160,25 @@ class Person(models.Model):
def to_string(self, commit=False): def to_string(self, commit=False):
if commit: if commit:
#generate commit-string #generate commit-string
print '' print self.to_dict()
else: else:
scratch = 'Name'.ljust(15, ' ') + ':' format = '%-10s: %50s \n'
scratch += ' '.join((first_name,last_name)) 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)
return scratch return scratch
def to_dict(self):
dict = {}
dict['action'] = 'edit-person'
dict['id'] = self.id
dict['first_name'] = self.first_name
dict['last_name'] = self.last_name
return dict
def __unicode__(self): def __unicode__(self):

View File

@ -39,12 +39,13 @@ def remove_duplicates(list):
def search_person_cmd(search_strings, search_description=False): def search_person_cmd(search_strings, search_description=False):
people = search_person(search_strings, search_description) people = search_person(search_strings, search_description)
format = '%-20s %-10s %-70s' #format = '%-20s %-10s %-70s'
for person in people: for person in people:
name = cut_str(person.first_name+' '+person.last_name, 20) print person.to_string()
p_id = cut_str(person.id, 10) # name = cut_str(person.first_name+' '+person.last_name, 20)
books = cut_str(', '.join(map(lambda x: x.book.title, person.books.all())), 70) # p_id = cut_str(person.id, 10)
print format % (name,p_id,books) # books = cut_str(', '.join(map(lambda x: x.book.title, person.books.all())), 70)
# print format % (name,p_id,books)
def search_person(search_strings, search_description=False): def search_person(search_strings, search_description=False):
basic_query=Person.objects.select_related('books__book__alt_titles') basic_query=Person.objects.select_related('books__book__alt_titles')