Merge lp:~suutari-olli/openlp/fix-openlp-importer into lp:openlp

Proposed by Azaziah
Status: Work in progress
Proposed branch: lp:~suutari-olli/openlp/fix-openlp-importer
Merge into: lp:openlp
Diff against target: 102 lines (+31/-7)
2 files modified
openlp/plugins/songs/lib/importers/openlp.py (+30/-6)
openlp/plugins/songs/lib/importers/songimport.py (+1/-1)
To merge this branch: bzr merge lp:~suutari-olli/openlp/fix-openlp-importer
Reviewer Review Type Date Requested Status
Tim Bentley Pending
Review via email: mp+314297@code.launchpad.net

This proposal supersedes a proposal from 2017-01-08.

Description of the change

- For diff (trunk)

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Question and no tests Sorry!

review: Needs Fixing
Revision history for this message
Azaziah (suutari-olli) wrote : Posted in a previous version of this proposal

I don't understand the question, and this branch is still a work in progress
- "proposals" are only for diff for now.

2718. By Azaziah

- This is broken, attempted to fix author types on import

Unmerged revisions

2718. By Azaziah

- This is broken, attempted to fix author types on import

2717. By Azaziah

- Fixed bug #1632567

2716. By Azaziah

- Better fix, now checks for songbook entry 1st.

2715. By Azaziah

- Fixed bug: 1652003

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/songs/lib/importers/openlp.py'
--- openlp/plugins/songs/lib/importers/openlp.py 2016-12-31 11:01:36 +0000
+++ openlp/plugins/songs/lib/importers/openlp.py 2017-01-12 13:37:17 +0000
@@ -33,7 +33,7 @@
33from openlp.core.lib.db import BaseModel33from openlp.core.lib.db import BaseModel
34from openlp.core.ui.lib.wizard import WizardStrings34from openlp.core.ui.lib.wizard import WizardStrings
35from openlp.plugins.songs.lib import clean_song35from openlp.plugins.songs.lib import clean_song
36from openlp.plugins.songs.lib.db import Author, Book, Song, Topic, MediaFile36from openlp.plugins.songs.lib.db import Author, AuthorSong, Book, Song, Topic, MediaFile
37from .songimport import SongImport37from .songimport import SongImport
3838
39log = logging.getLogger(__name__)39log = logging.getLogger(__name__)
@@ -67,6 +67,12 @@
67 """67 """
68 pass68 pass
6969
70 class OldAuthorSong(BaseModel):
71 """
72 Maps to the authors_songs songs table
73 """
74 pass
75
70 class OldBook(BaseModel):76 class OldBook(BaseModel):
71 """77 """
72 Maps to the songbooks table78 Maps to the songbooks table
@@ -142,8 +148,10 @@
142 # Set up the songs relationships148 # Set up the songs relationships
143 song_props = {149 song_props = {
144 'authors': relation(OldAuthor, backref='songs', secondary=source_authors_songs_table),150 'authors': relation(OldAuthor, backref='songs', secondary=source_authors_songs_table),
145 'topics': relation(OldTopic, backref='songs', secondary=source_songs_topics_table)151 'topics': relation(OldTopic, backref='songs', secondary=source_songs_topics_table),
152 'authors_songs': relation(OldAuthorSong, backref='songs', secondary=source_authors_songs_table)
146 }153 }
154
147 if has_media_files:155 if has_media_files:
148 if isinstance(source_media_files_songs_table, Table):156 if isinstance(source_media_files_songs_table, Table):
149 song_props['media_files'] = relation(OldMediaFile, backref='songs',157 song_props['media_files'] = relation(OldMediaFile, backref='songs',
@@ -163,6 +171,10 @@
163 except UnmappedClassError:171 except UnmappedClassError:
164 mapper(OldAuthor, source_authors_table)172 mapper(OldAuthor, source_authors_table)
165 try:173 try:
174 class_mapper(OldAuthorSong)
175 except UnmappedClassError:
176 mapper(OldAuthorSong, source_authors_table)
177 try:
166 class_mapper(OldBook)178 class_mapper(OldBook)
167 except UnmappedClassError:179 except UnmappedClassError:
168 mapper(OldBook, source_song_books_table)180 mapper(OldBook, source_song_books_table)
@@ -201,13 +213,19 @@
201 # Find or create all the authors and add them to the new song object213 # Find or create all the authors and add them to the new song object
202 for author in song.authors:214 for author in song.authors:
203 existing_author = self.manager.get_object_filtered(Author, Author.display_name == author.display_name)215 existing_author = self.manager.get_object_filtered(Author, Author.display_name == author.display_name)
216 # Get the author type.
217 a_type = self.manager.get_object_filtered(AuthorSong, AuthorSong.author_type == AuthorSong.author_type)
204 if not existing_author:218 if not existing_author:
205 existing_author = Author.populate(219 existing_author = Author.populate(
206 first_name=author.first_name,220 first_name=author.first_name,
207 last_name=author.last_name,221 last_name=author.last_name,
208 display_name=author.display_name)222 display_name=author.display_name,
209 new_song.add_author(existing_author)223 )
224
225 new_song.add_author(existing_author, a_type)
226
210 # Find or create all the topics and add them to the new song object227 # Find or create all the topics and add them to the new song object
228
211 if song.topics:229 if song.topics:
212 for topic in song.topics:230 for topic in song.topics:
213 existing_topic = self.manager.get_object_filtered(Topic, Topic.name == topic.name)231 existing_topic = self.manager.get_object_filtered(Topic, Topic.name == topic.name)
@@ -221,11 +239,17 @@
221 if not existing_book:239 if not existing_book:
222 existing_book = Book.populate(name=entry.songbook.name, publisher=entry.songbook.publisher)240 existing_book = Book.populate(name=entry.songbook.name, publisher=entry.songbook.publisher)
223 new_song.add_songbook_entry(existing_book, entry.entry)241 new_song.add_songbook_entry(existing_book, entry.entry)
224 elif song.book:242 elif hasattr(song, 'book') and song.book:
225 existing_book = self.manager.get_object_filtered(Book, Book.name == song.book.name)243 existing_book = self.manager.get_object_filtered(Book, Book.name == song.book.name)
226 if not existing_book:244 if not existing_book:
227 existing_book = Book.populate(name=song.book.name, publisher=song.book.publisher)245 existing_book = Book.populate(name=song.book.name, publisher=song.book.publisher)
228 new_song.add_songbook_entry(existing_book, '')246 # Get the song_number from "songs" table "song_number" field. (This is db structure from 2.2.1)
247 # If there's a number, add it to the song, otherwise it will be "".
248 existing_number = song.song_number
249 if existing_number:
250 new_song.add_songbook_entry(existing_book, existing_number)
251 else:
252 new_song.add_songbook_entry(existing_book, "")
229 # Find or create all the media files and add them to the new song object253 # Find or create all the media files and add them to the new song object
230 if has_media_files and song.media_files:254 if has_media_files and song.media_files:
231 for media_file in song.media_files:255 for media_file in song.media_files:
232256
=== modified file 'openlp/plugins/songs/lib/importers/songimport.py'
--- openlp/plugins/songs/lib/importers/songimport.py 2016-12-31 11:01:36 +0000
+++ openlp/plugins/songs/lib/importers/songimport.py 2017-01-12 13:37:17 +0000
@@ -30,7 +30,7 @@
30from openlp.core.common import Registry, AppLocation, check_directory_exists, translate30from openlp.core.common import Registry, AppLocation, check_directory_exists, translate
31from openlp.core.ui.lib.wizard import WizardStrings31from openlp.core.ui.lib.wizard import WizardStrings
32from openlp.plugins.songs.lib import clean_song, VerseType32from openlp.plugins.songs.lib import clean_song, VerseType
33from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile33from openlp.plugins.songs.lib.db import Song, Author, AuthorType, Topic, Book, MediaFile
34from openlp.plugins.songs.lib.ui import SongStrings34from openlp.plugins.songs.lib.ui import SongStrings
35from openlp.plugins.songs.lib.openlyricsxml import SongXML35from openlp.plugins.songs.lib.openlyricsxml import SongXML
3636