Use populate() for DB objects

bzr-revno: 945
This commit is contained in:
Jon Tibble 2010-07-16 12:50:37 +01:00
commit d04a09f317

View File

@ -303,28 +303,22 @@ class SongImport(object):
author = self.manager.get_object_filtered(Author, author = self.manager.get_object_filtered(Author,
Author.display_name == authortext) Author.display_name == authortext)
if author is None: if author is None:
author = Author() author = Author.populate(display_name = authortext,
author.display_name = authortext last_name=authortext.split(u' ')[-1],
author.last_name = authortext.split(u' ')[-1] first_name=u' '.join(authortext.split(u' ')[:-1]))
author.first_name = u' '.join(authortext.split(u' ')[:-1])
self.manager.save_object(author)
song.authors.append(author) song.authors.append(author)
if self.song_book_name: if self.song_book_name:
song_book = self.manager.get_object_filtered(Book, song_book = self.manager.get_object_filtered(Book,
Book.name == self.song_book_name) Book.name == self.song_book_name)
if song_book is None: if song_book is None:
song_book = Book() song_book = Book.populate(name=self.song_book_name,
song_book.name = self.song_book_name publisher=self.song_book_pub)
song_book.publisher = self.song_book_pub song.book = song_book
self.manager.save_object(song_book)
song.song_book_id = song_book.id
for topictext in self.topics: for topictext in self.topics:
topic = self.manager.get_object_filtered(Topic, topic = self.manager.get_object_filtered(Topic,
Topic.name == topictext) Topic.name == topictext)
if topic is None: if topic is None:
topic = Topic() topic = Topic.populate(name=topictext)
topic.name = topictext
self.manager.save_object(topic)
song.topics.append(topictext) song.topics.append(topictext)
self.manager.save_object(song) self.manager.save_object(song)