← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/bug-863845 into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/bug-863845 into lp:openlp.

Requested reviews:
  Jon Tibble (meths)
  Andreas Preikschat (googol)
  Tim Bentley (trb143)
Related bugs:
  Bug #899532 in OpenLP: "OpenLP 2 database import fails when using an old database"
  https://bugs.launchpad.net/openlp/+bug/899532

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/bug-863845/+merge/84387

Fix various OpenLP 2 import problems. This fixes bugs #863845 and #899532.
-- 
https://code.launchpad.net/~raoul-snyman/openlp/bug-863845/+merge/84387
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/olpimport.py'
--- openlp/plugins/songs/lib/olpimport.py	2011-12-02 20:17:57 +0000
+++ openlp/plugins/songs/lib/olpimport.py	2011-12-03 21:53:32 +0000
@@ -39,7 +39,7 @@
 from openlp.core.lib.db import BaseModel
 from openlp.core.ui.wizard import WizardStrings
 from openlp.plugins.songs.lib import clean_song
-from openlp.plugins.songs.lib.db import Author, Book, MediaFile, Song, Topic
+from openlp.plugins.songs.lib.db import Author, Book, Song, Topic, MediaFile
 from songimport import SongImport
 
 log = logging.getLogger(__name__)
@@ -121,6 +121,7 @@
         source_topics_table = source_meta.tables[u'topics']
         source_authors_songs_table = source_meta.tables[u'authors_songs']
         source_songs_topics_table = source_meta.tables[u'songs_topics']
+        source_media_files_songs_table = None
         if has_media_files:
             source_media_files_table = source_meta.tables[u'media_files']
             source_media_files_songs_table = \
@@ -137,13 +138,14 @@
             secondary=source_songs_topics_table)
         }
         if has_media_files:
-            if source_media_files_songs_table:
+            if source_media_files_songs_table is not None:
                 song_props['media_files'] = relation(OldMediaFile,
                     backref='songs',
                     secondary=source_media_files_songs_table)
             else:
                 song_props['media_files'] = relation(OldMediaFile,
-                    backref='songs')
+                    backref='songs', primaryjoin=source_songs_table.c.id==OldMediaFile.song_id,
+                    foreign_keys=[source_media_files_table.c.song_id])
         try:
             class_mapper(OldAuthor)
         except UnmappedClassError: