Add support for author types to the OpenLP importer

This commit is contained in:
Raoul Snyman 2017-03-08 16:32:16 -07:00
parent 3ff851b064
commit 8850ab2fe3
1 changed files with 31 additions and 2 deletions

View File

@ -61,6 +61,12 @@ class OpenLPSongImport(SongImport):
:param progress_dialog: The QProgressDialog used when importing songs from the FRW.
"""
class OldAuthorSong(BaseModel):
"""
Maps to the authors table
"""
pass
class OldAuthor(BaseModel):
"""
Maps to the authors table
@ -117,6 +123,10 @@ class OpenLPSongImport(SongImport):
has_songs_books = True
else:
has_songs_books = False
if 'authors_songs' in list(source_meta.tables.keys()):
has_authors_songs = True
else:
has_authors_songs = False
# Load up the tabls and map them out
source_authors_table = source_meta.tables['authors']
source_song_books_table = source_meta.tables['song_books']
@ -139,6 +149,10 @@ class OpenLPSongImport(SongImport):
class_mapper(OldSongBookEntry)
except UnmappedClassError:
mapper(OldSongBookEntry, source_songs_songbooks_table, properties={'songbook': relation(OldBook)})
if has_authors_songs and 'author_type' in source_authors_songs_table.c.values():
has_author_type = True
else:
has_author_type = False
# Set up the songs relationships
song_props = {
'authors': relation(OldAuthor, backref='songs', secondary=source_authors_songs_table),
@ -157,6 +171,8 @@ class OpenLPSongImport(SongImport):
song_props['songbook_entries'] = relation(OldSongBookEntry, backref='song', cascade='all, delete-orphan')
else:
song_props['book'] = relation(OldBook, backref='songs')
if has_authors_songs:
song_props['authors_songs'] = relation(OldAuthorSong)
# Map the rest of the tables
try:
class_mapper(OldAuthor)
@ -174,6 +190,11 @@ class OpenLPSongImport(SongImport):
class_mapper(OldTopic)
except UnmappedClassError:
mapper(OldTopic, source_topics_table)
if has_authors_songs:
try:
class_mapper(OldAuthorSong)
except UnmappedClassError:
mapper(OldAuthorSong, source_authors_songs_table)
source_songs = self.source_session.query(OldSong).all()
if self.import_wizard:
@ -205,8 +226,16 @@ class OpenLPSongImport(SongImport):
existing_author = Author.populate(
first_name=author.first_name,
last_name=author.last_name,
display_name=author.display_name)
new_song.add_author(existing_author)
display_name=author.display_name
)
# if this is a new database, we need to import the author type too
author_type = None
if has_author_type:
for author_song in song.authors_songs:
if author_song.author_id == author.id:
author_type = author_song.author_type
break
new_song.add_author(existing_author, author_type)
# Find or create all the topics and add them to the new song object
if song.topics:
for topic in song.topics: