forked from openlp/openlp
Add support for author types to the OpenLP importer
This commit is contained in:
parent
3ff851b064
commit
8850ab2fe3
@ -61,6 +61,12 @@ class OpenLPSongImport(SongImport):
|
|||||||
:param progress_dialog: The QProgressDialog used when importing songs from the FRW.
|
:param progress_dialog: The QProgressDialog used when importing songs from the FRW.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class OldAuthorSong(BaseModel):
|
||||||
|
"""
|
||||||
|
Maps to the authors table
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class OldAuthor(BaseModel):
|
class OldAuthor(BaseModel):
|
||||||
"""
|
"""
|
||||||
Maps to the authors table
|
Maps to the authors table
|
||||||
@ -117,6 +123,10 @@ class OpenLPSongImport(SongImport):
|
|||||||
has_songs_books = True
|
has_songs_books = True
|
||||||
else:
|
else:
|
||||||
has_songs_books = False
|
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
|
# Load up the tabls and map them out
|
||||||
source_authors_table = source_meta.tables['authors']
|
source_authors_table = source_meta.tables['authors']
|
||||||
source_song_books_table = source_meta.tables['song_books']
|
source_song_books_table = source_meta.tables['song_books']
|
||||||
@ -139,6 +149,10 @@ class OpenLPSongImport(SongImport):
|
|||||||
class_mapper(OldSongBookEntry)
|
class_mapper(OldSongBookEntry)
|
||||||
except UnmappedClassError:
|
except UnmappedClassError:
|
||||||
mapper(OldSongBookEntry, source_songs_songbooks_table, properties={'songbook': relation(OldBook)})
|
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
|
# Set up the songs relationships
|
||||||
song_props = {
|
song_props = {
|
||||||
'authors': relation(OldAuthor, backref='songs', secondary=source_authors_songs_table),
|
'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')
|
song_props['songbook_entries'] = relation(OldSongBookEntry, backref='song', cascade='all, delete-orphan')
|
||||||
else:
|
else:
|
||||||
song_props['book'] = relation(OldBook, backref='songs')
|
song_props['book'] = relation(OldBook, backref='songs')
|
||||||
|
if has_authors_songs:
|
||||||
|
song_props['authors_songs'] = relation(OldAuthorSong)
|
||||||
# Map the rest of the tables
|
# Map the rest of the tables
|
||||||
try:
|
try:
|
||||||
class_mapper(OldAuthor)
|
class_mapper(OldAuthor)
|
||||||
@ -174,6 +190,11 @@ class OpenLPSongImport(SongImport):
|
|||||||
class_mapper(OldTopic)
|
class_mapper(OldTopic)
|
||||||
except UnmappedClassError:
|
except UnmappedClassError:
|
||||||
mapper(OldTopic, source_topics_table)
|
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()
|
source_songs = self.source_session.query(OldSong).all()
|
||||||
if self.import_wizard:
|
if self.import_wizard:
|
||||||
@ -205,8 +226,16 @@ class OpenLPSongImport(SongImport):
|
|||||||
existing_author = Author.populate(
|
existing_author = Author.populate(
|
||||||
first_name=author.first_name,
|
first_name=author.first_name,
|
||||||
last_name=author.last_name,
|
last_name=author.last_name,
|
||||||
display_name=author.display_name)
|
display_name=author.display_name
|
||||||
new_song.add_author(existing_author)
|
)
|
||||||
|
# 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
|
# Find or create all the topics and add them to the new song object
|
||||||
if song.topics:
|
if song.topics:
|
||||||
for topic in song.topics:
|
for topic in song.topics:
|
||||||
|
Loading…
Reference in New Issue
Block a user