← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/trivial into lp:openlp

 

googol has proposed merging lp:~googol-hush/openlp/trivial into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman): error in logic


- added error messages
- comments/line length clean up
-- 
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/30179
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/ui/maindisplay.py'
--- openlp/core/ui/maindisplay.py	2010-07-15 18:07:23 +0000
+++ openlp/core/ui/maindisplay.py	2010-07-17 16:08:42 +0000
@@ -167,7 +167,7 @@
 
     def keyPressEvent(self, event):
         if isinstance(event, QtGui.QKeyEvent):
-            #here accept the event and do something
+            # Here accept the event and do something.
             if event.key() == QtCore.Qt.Key_Up:
                 Receiver.send_message(u'slidecontroller_live_previous')
                 event.accept()
@@ -233,8 +233,8 @@
         self.setupBlank()
         self.blankFrame = None
         self.frame = None
-        #Hide desktop for now until we know where to put it
-        #and what size it should be.
+        # Hide desktop for now until we know where to put it
+        # and what size it should be.
         self.setVisible(False)
 
     def setup(self):
@@ -245,13 +245,12 @@
             self.screens, self.screens.monitor_number))
         self.setVisible(False)
         self.screen = self.screens.current
-        #Sort out screen locations and sizes
+        # Sort out screen locations and sizes.
         self.setGeometry(self.screen[u'size'])
-        self.scene.setSceneRect(0, 0, self.size().width(),
-            self.size().height())
+        self.scene.setSceneRect(0, 0, self.size().width(), self.size().height())
         self.webView.setGeometry(0, 0, self.size().width(),
             self.size().height())
-        #Build a custom splash screen
+        # Build a custom splash screen.
         self.initialFrame = QtGui.QImage(
             self.screen[u'size'].width(),
             self.screen[u'size'].height(),
@@ -266,7 +265,7 @@
             splash_image)
         self.displayImage(self.initialFrame)
         self.repaint()
-        #Build a Black screen
+        # Build a Black screen.
         painter = QtGui.QPainter()
         self.blankFrame = QtGui.QImage(
             self.screen[u'size'].width(),
@@ -274,11 +273,11 @@
             QtGui.QImage.Format_ARGB32_Premultiplied)
         painter.begin(self.blankFrame)
         painter.fillRect(self.blankFrame.rect(), QtCore.Qt.black)
-        #build a blank transparent image
+        # Build a blank transparent image.
         self.transparent = QtGui.QPixmap(
             self.screen[u'size'].width(), self.screen[u'size'].height())
         self.transparent.fill(QtCore.Qt.transparent)
-#        self.displayText.setPixmap(self.transparent)
+        #self.displayText.setPixmap(self.transparent)
         #self.frameView(self.transparent)
         # To display or not to display?
         if not self.screen[u'primary']:
@@ -371,7 +370,7 @@
         self.displayBlank.setPixmap(self.transparent)
         if self.isHidden():
             self.setVisible(True)
-        #Trigger actions when display is active again
+        # Trigger actions when display is active again.
         Receiver.send_message(u'maindisplay_active')
 
     def addImageWithText(self, frame):
@@ -421,8 +420,7 @@
         log.debug(u'adddisplayVideo')
         self.displayImage(self.transparent)
         self.videoDisplay.setHtml(HTMLVIDEO %
-            (path, self.screen[u'size'].width(),
-            self.screen[u'size'].height()))
+            (path, self.screen[u'size'].width(), self.screen[u'size'].height()))
 
     def frameView(self, frame, transition=False):
         """
@@ -510,7 +508,7 @@
 
     def keyPressEvent(self, event):
         if isinstance(event, QtGui.QKeyEvent):
-            #here accept the event and do something
+            # Here accept the event and do something.
             if event.key() == QtCore.Qt.Key_Escape:
                 self.onMediaStop()
                 event.accept()
@@ -525,7 +523,7 @@
         log.debug(u'VideoDisplay Setup %s for %s ' % (self.screens,
             self.screens.monitor_number))
         self.screen = self.screens.current
-        #Sort out screen locations and sizes
+        # Sort out screen locations and sizes.
         self.setGeometry(self.screen[u'size'])
         # To display or not to display?
         if not self.screen[u'primary']: # and self.isVisible():
@@ -552,10 +550,10 @@
 #        if it is triggered from the plugin
 #        """
 #        log.debug(u'VideoDisplay Queue new media message %s' % message)
-#        #If not file take the stored one
+#        # If not file take the stored one.
 #        if not message:
 #            message = self.message
-#        # still no file name then stop as it was a normal video stopping
+#        # Still no file name then stop as it was a normal video stopping.
 #        if message:
 #            self.mediaObject.setCurrentSource(Phonon.MediaSource(message))
 #            self.message = message

=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py	2010-07-12 14:32:48 +0000
+++ openlp/core/ui/mainwindow.py	2010-07-17 16:08:42 +0000
@@ -114,7 +114,7 @@
         MainWindow.setSizePolicy(sizePolicy)
         MainIcon = build_icon(u':/icon/openlp-logo-16x16.png')
         MainWindow.setWindowIcon(MainIcon)
-        # Set up the main container, which contains all the other form widgets
+        # Set up the main container, which contains all the other form widgets.
         self.MainContent = QtGui.QWidget(MainWindow)
         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
             QtGui.QSizePolicy.Expanding)

=== modified file 'openlp/plugins/bibles/bibleplugin.py'
--- openlp/plugins/bibles/bibleplugin.py	2010-07-12 21:11:00 +0000
+++ openlp/plugins/bibles/bibleplugin.py	2010-07-17 16:08:42 +0000
@@ -40,7 +40,7 @@
         self.weight = -9
         self.icon_path = u':/plugins/plugin_bibles.png'
         self.icon = build_icon(self.icon_path)
-        #Register the bible Manager
+        # Register the bible Manager.
         self.status = PluginStatus.Active
         self.manager = None
 
@@ -62,7 +62,7 @@
         return BiblesTab(self.name)
 
     def getMediaManagerItem(self):
-        # Create the BibleManagerItem object
+        # Create the BibleManagerItem object.
         return BibleMediaItem(self, self.icon, self.name)
 
     def addImportMenuItem(self, import_menu):
@@ -71,7 +71,7 @@
         import_menu.addAction(self.ImportBibleItem)
         self.ImportBibleItem.setText(
             translate('BiblePlugin', '&Bible'))
-        # Signals and slots
+        # signals and slots
         QtCore.QObject.connect(self.ImportBibleItem,
             QtCore.SIGNAL(u'triggered()'), self.onBibleImportClick)
         self.ImportBibleItem.setVisible(False)

=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py	2010-07-08 13:50:06 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py	2010-07-17 16:08:42 +0000
@@ -129,8 +129,7 @@
         self.QuickClearLabel.setObjectName(u'QuickSearchLabel')
         self.QuickLayout.addWidget(self.QuickClearLabel, 4, 0, 1, 1)
         self.ClearQuickSearchComboBox = QtGui.QComboBox(self.QuickTab)
-        self.ClearQuickSearchComboBox.setObjectName(
-            u'ClearQuickSearchComboBox')
+        self.ClearQuickSearchComboBox.setObjectName(u'ClearQuickSearchComboBox')
         self.QuickLayout.addWidget(self.ClearQuickSearchComboBox, 4, 1, 1, 2)
         self.QuickSearchButtonLayout = QtGui.QHBoxLayout()
         self.QuickSearchButtonLayout.setMargin(0)
@@ -168,8 +167,7 @@
         self.AdvancedVersionComboBox.setObjectName(u'AdvancedVersionComboBox')
         self.AdvancedLayout.addWidget(self.AdvancedVersionComboBox, 0, 1, 1, 2)
         self.AdvancedSecondBibleLabel = QtGui.QLabel(self.AdvancedTab)
-        self.AdvancedSecondBibleLabel.setObjectName(
-            u'AdvancedSecondBibleLabel')
+        self.AdvancedSecondBibleLabel.setObjectName(u'AdvancedSecondBibleLabel')
         self.AdvancedLayout.addWidget(self.AdvancedSecondBibleLabel, 1, 0, 1, 1)
         self.AdvancedSecondBibleComboBox = QtGui.QComboBox(self.AdvancedTab)
         self.AdvancedSecondBibleComboBox.setSizeAdjustPolicy(
@@ -223,8 +221,7 @@
             u'AdvancedSearchButtonLayout')
         self.AdvancedSearchButtonSpacer = QtGui.QSpacerItem(40, 20,
             QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
-        self.AdvancedSearchButtonLayout.addItem(
-            self.AdvancedSearchButtonSpacer)
+        self.AdvancedSearchButtonLayout.addItem(self.AdvancedSearchButtonSpacer)
         self.AdvancedSearchButton = QtGui.QPushButton(self.AdvancedTab)
         self.AdvancedSearchButton.setObjectName(u'AdvancedSearchButton')
         self.AdvancedSearchButtonLayout.addWidget(self.AdvancedSearchButton)
@@ -618,8 +615,7 @@
         else:
             self.AdvancedSearchButton.setEnabled(True)
             self.AdvancedMessage.setText(u'')
-            self.adjustComboBox(1, self.chapters_from,
-                self.AdvancedFromChapter)
+            self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
             self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
             self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
             self.adjustComboBox(1, self.verses, self.AdvancedToVerse)

=== modified file 'openlp/plugins/songs/forms/authorsform.py'
--- openlp/plugins/songs/forms/authorsform.py	2010-06-22 14:34:03 +0000
+++ openlp/plugins/songs/forms/authorsform.py	2010-07-17 16:08:42 +0000
@@ -97,7 +97,7 @@
             if QtGui.QMessageBox.critical(
                     self, translate('SongsPlugin.AuthorsForm', 'Error'),
                     translate('SongsPlugin.AuthorsForm',
-                        'You haven\'t set a display name for the '
+                        'You have not set a display name for the '
                         'author, would you like me to combine the first and '
                         'last names for you?'),
                     QtGui.QMessageBox.StandardButtons(

=== modified file 'openlp/plugins/songs/forms/editsongdialog.py'
--- openlp/plugins/songs/forms/editsongdialog.py	2010-07-16 12:31:47 +0000
+++ openlp/plugins/songs/forms/editsongdialog.py	2010-07-17 16:08:42 +0000
@@ -430,7 +430,7 @@
         self.AuthorRemoveButton.setText(
             translate('SongsPlugin.EditSongForm', '&Remove'))
         self.MaintenanceButton.setText(translate('SongsPlugin.EditSongForm',
-            '&Manage Authors, Topics, Books'))
+            '&Manage Authors, Topics, Song Books'))
         self.TopicGroupBox.setTitle(
             translate('SongsPlugin.EditSongForm', 'Topic'))
         self.TopicAddButton.setText(
@@ -441,7 +441,7 @@
             translate('SongsPlugin.EditSongForm', 'Song Book'))
         self.SongTabWidget.setTabText(
             self.SongTabWidget.indexOf(self.AuthorsTab),
-            translate('SongsPlugin.EditSongForm', 'Authors, Topics && Book'))
+            translate('SongsPlugin.EditSongForm', 'Authors, Topics && Song Book'))
         self.ThemeGroupBox.setTitle(
             translate('SongsPlugin.EditSongForm', 'Theme'))
         self.ThemeAddButton.setText(

=== modified file 'openlp/plugins/songs/forms/songbookdialog.py'
--- openlp/plugins/songs/forms/songbookdialog.py	2010-06-22 14:34:03 +0000
+++ openlp/plugins/songs/forms/songbookdialog.py	2010-07-17 16:08:42 +0000
@@ -68,7 +68,7 @@
 
     def retranslateUi(self, SongBookDialog):
         SongBookDialog.setWindowTitle(
-            translate('SongsPlugin.SongBookForm', 'Edit Book'))
+            translate('SongsPlugin.SongBookForm', 'Song Book Maintenance'))
         self.NameLabel.setText(translate('SongsPlugin.SongBookForm', '&Name:'))
         self.PublisherLabel.setText(
             translate('SongsPlugin.SongBookForm', '&Publisher:'))

=== modified file 'openlp/plugins/songs/forms/songmaintenancedialog.py'
--- openlp/plugins/songs/forms/songmaintenancedialog.py	2010-06-18 19:55:45 +0000
+++ openlp/plugins/songs/forms/songmaintenancedialog.py	2010-07-17 16:08:42 +0000
@@ -217,7 +217,7 @@
         self.TypeListWidget.item(1).setText(
             translate('SongsPlugin.SongMaintenanceForm', 'Topics'))
         self.TypeListWidget.item(2).setText(
-            translate('SongsPlugin.SongMaintenanceForm', 'Books/Hymnals'))
+            translate('SongsPlugin.SongMaintenanceForm', 'Song Books'))
         self.AuthorAddButton.setText(
             translate('SongsPlugin.SongMaintenanceForm', '&Add'))
         self.AuthorEditButton.setText(

=== modified file 'openlp/plugins/songs/forms/songmaintenanceform.py'
--- openlp/plugins/songs/forms/songmaintenanceform.py	2010-07-16 18:53:49 +0000
+++ openlp/plugins/songs/forms/songmaintenanceform.py	2010-07-17 16:08:42 +0000
@@ -26,9 +26,10 @@
 from PyQt4 import QtGui, QtCore
 from sqlalchemy.sql import and_
 
-from openlp.core.lib import translate
+from openlp.core.lib import Receiver, translate
 from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm
-from openlp.plugins.songs.lib.db import Author, Book, Topic
+from openlp.plugins.songs.lib.db import Author, Book, Topic, Song, \
+    SongsTopics, AuthorsSongs
 from songmaintenancedialog import Ui_SongMaintenanceDialog
 
 class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
@@ -140,13 +141,10 @@
         Returns False if the given Author is already in the list otherwise
         True.
         """
-        authors = self.songmanager.get_all_objects_filtered(Author, 
-            and_(
-                Author.first_name == new_author.first_name, 
-                Author.last_name == new_author.last_name, 
-                Author.display_name == new_author.display_name
-                )
-            )
+        authors = self.songmanager.get_all_objects_filtered(Author,
+            and_(Author.first_name == new_author.first_name,
+                Author.last_name == new_author.last_name,
+                Author.display_name == new_author.display_name))
         if len(authors) > 0:
             # If we edit an existing Author, we need to make sure that we do
             # not return False when nothing has changed (because this would
@@ -186,7 +184,7 @@
         Returns False if the given Book is already in the list otherwise True.
         """
         books = self.songmanager.get_all_objects_filtered(Book,
-            and_(Book.name == new_book.name, 
+            and_(Book.name == new_book.name,
                 Book.publisher == new_book.publisher))
         if len(books) > 0:
             # If we edit an existing Book, we need to make sure that we do
@@ -212,11 +210,16 @@
             if self.checkAuthor(author):
                 if self.songmanager.save_object(author):
                     self.resetAuthors()
+                else:
+                    QtGui.QMessageBox.critical(self,
+                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                        translate('SongsPlugin.SongMaintenanceForm',
+                        'Could not add your author.'))
             else:
                 QtGui.QMessageBox.critical(self,
                     translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                     translate('SongsPlugin.SongMaintenanceForm',
-                    'Could not add your author.'))
+                    'This author already exists.'))
 
     def onTopicAddButtonClick(self):
         if self.topicform.exec_():
@@ -224,25 +227,34 @@
             if self.checkTopic(topic):
                 if self.songmanager.save_object(topic):
                     self.resetTopics()
+                else:
+                    QtGui.QMessageBox.critical(self,
+                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                        translate('SongsPlugin.SongMaintenanceForm',
+                        'Could not add your topic.'))
             else:
                 QtGui.QMessageBox.critical(self,
                     translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                     translate('SongsPlugin.SongMaintenanceForm',
-                    'Could not add your topic.'))
+                    'This topic already exists.'))
 
     def onBookAddButtonClick(self):
         if self.bookform.exec_():
-            book = Book.populate(
-                name=unicode(self.bookform.NameEdit.text()),
+            book = Book.populate(name=unicode(self.bookform.NameEdit.text()),
                 publisher=unicode(self.bookform.PublisherEdit.text()))
             if self.checkBook(book):
                 if self.songmanager.save_object(book):
                     self.resetBooks()
+                else:
+                    QtGui.QMessageBox.critical(self,
+                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                        translate('SongsPlugin.SongMaintenanceForm',
+                        'Could not add your book.'))
             else:
                 QtGui.QMessageBox.critical(self,
                     translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                     translate('SongsPlugin.SongMaintenanceForm',
-                    'Could not add your book.'))
+                    'This book already exists.'))
 
     def onAuthorEditButtonClick(self):
         author_id = self._getCurrentItemId(self.AuthorsListWidget)
@@ -266,6 +278,24 @@
                 if self.checkAuthor(author, True):
                     if self.songmanager.save_object(author):
                         self.resetAuthors()
+                        Receiver.send_message(u'songs_load_list')
+                    else:
+                        QtGui.QMessageBox.critical(self,
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Error'),
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Could not save your changes.'))
+                elif QtGui.QMessageBox.critical(self,
+                    translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                    translate('SongsPlugin.SongMaintenanceForm', 'The author %s'
+                    ' already exists. Would you like to make songs with author '
+                    '%s use the existing author %s?' % (author.display_name,
+                    temp_display_name, author.display_name)),
+                    QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | \
+                    QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
+                    self.mergeAuthors(author)
+                    self.resetAuthors()
+                    Receiver.send_message(u'songs_load_list')
                 else:
                     # We restore the author's old first and last name as well as
                     # his display name.
@@ -275,7 +305,8 @@
                     QtGui.QMessageBox.critical(self,
                         translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                         translate('SongsPlugin.SongMaintenanceForm',
-                        'Could not save your author.'))
+                        'Could not save your modified author, because he '
+                        'already exists.'))
 
     def onTopicEditButtonClick(self):
         topic_id = self._getCurrentItemId(self.TopicsListWidget)
@@ -289,13 +320,30 @@
                 if self.checkTopic(topic, True):
                     if self.songmanager.save_object(topic):
                         self.resetTopics()
+                    else:
+                        QtGui.QMessageBox.critical(self,
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Error'),
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Could not save your changes.'))
+                elif QtGui.QMessageBox.critical(self,
+                    translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                    translate('SongsPlugin.SongMaintenanceForm', 'The topic %s '
+                    'already exists. Would you like to make songs with topic %s'
+                    ' use the existing topic %s?' % (topic.name, temp_name,
+                    topic.name)),
+                    QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | \
+                    QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
+                    self.mergeTopics(topic)
+                    self.resetTopics()
                 else:
                     # We restore the topics's old name.
                     topic.name = temp_name
                     QtGui.QMessageBox.critical(self,
                         translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                         translate('SongsPlugin.SongMaintenanceForm',
-                        'Could not save your topic.'))
+                        'Could not save your modified topic, because it '
+                        'already exists.'))
 
     def onBookEditButtonClick(self):
         book_id = self._getCurrentItemId(self.BooksListWidget)
@@ -313,18 +361,96 @@
                 if self.checkBook(book, True):
                     if self.songmanager.save_object(book):
                         self.resetBooks()
+                    else:
+                        QtGui.QMessageBox.critical(self,
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Error'),
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Could not save your changes.'))
+                elif QtGui.QMessageBox.critical(self,
+                    translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                    translate('SongsPlugin.SongMaintenanceForm', 'The book %s '
+                    'already exists. Would you like to make songs with book %s '
+                    'use the existing book %s?' % (book.name, temp_name,
+                    book.name)),
+                    QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | \
+                    QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
+                    self.mergeBooks(book)
+                    self.resetBooks()
                 else:
-                    # We restore the book's old name and publisher.
+                    # We restore the book's old name and publisher, because
+                    # the user did not want to merge the two topics.
                     book.name = temp_name
                     book.publisher = temp_publisher
-                    QtGui.QMessageBox.critical(self,
-                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
-                        translate('SongsPlugin.SongMaintenanceForm',
-                        'Could not save your book.'))
+
+    def mergeAuthors(self, existing_author):
+        '''
+        Merges two authors into one author.
+        
+        ``existing_author``
+            The author which will be deleted afterwards.
+        '''
+        new_author = self.songmanager.get_object_filtered(Author,
+            and_(Author.first_name == existing_author.first_name,
+                Author.last_name == existing_author.last_name, 
+                Author.display_name == existing_author.display_name))
+        songs = self.songmanager.get_all_objects_filtered(AuthorsSongs,
+            AuthorsSongs.author_id == existing_author.id)
+        for song in songs:
+            # We have to check if the song has already the new_author as author.
+            # If that is the case we must not change song.author_id to the
+            # new_author's id, because then they were not unique.
+            temp_song = self.songmanager.get_all_objects_filtered(AuthorsSongs,
+                and_(AuthorsSongs.author_id == new_author.id,
+                    AuthorsSongs.song_id == song.song_id))
+            if len(temp_song) < 1:
+                song.author_id = new_author.id
+                self.songmanager.save_object(song)
+        self.songmanager.delete_object(Author, existing_author.id)
+
+    def mergeTopics(self, existing_topic):
+        '''
+        Merges two topics into one topic.
+        
+        ``existing_topic``
+            The topic which will be deleted afterwards.
+        '''
+        new_topic = self.songmanager.get_object_filtered(Topic,
+            Topic.name == existing_topic.name)
+        songs = self.songmanager.get_all_objects_filtered(SongsTopics,
+            SongsTopics.topic_id == existing_topic.id)
+        for song in songs:
+            # We have to check if the song has already the new_topic as topic.
+            # If that is the case we must not change song.topic_id to the
+            # new_topic's id, because then they were not unique.
+            temp_song = self.songmanager.get_all_objects_filtered(SongsTopics,
+                and_(SongsTopics.topic_id == new_topic.id,
+                    SongsTopics.song_id == song.song_id))
+            if len(temp_song) < 1:
+                song.topic_id = new_topic.id
+                self.songmanager.save_object(song)
+        self.songmanager.delete_object(Topic, existing_topic.id)
+
+    def mergeBooks(self, existing_book):
+        '''
+        Merges two books into one book.
+        
+        ``existing_book``
+            The book which will be deleted afterwards.
+        '''
+        new_book = self.songmanager.get_object_filtered(Book,
+            and_(Book.name == existing_book.name,
+                Book.publisher == existing_book.publisher))
+        songs = self.songmanager.get_all_objects_filtered(Song,
+            Song.song_book_id == existing_book.id)
+        for song in songs:
+            song.song_book_id = new_book.id
+            self.songmanager.save_object(song)
+        self.songmanager.delete_object(Book, existing_book.id)
 
     def onAuthorDeleteButtonClick(self):
         """
-        Delete the author if the author is not attached to any songs
+        Delete the author if the author is not attached to any songs.
         """
         self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors,
             translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
@@ -337,7 +463,7 @@
 
     def onTopicDeleteButtonClick(self):
         """
-        Delete the Book is the Book is not attached to any songs
+        Delete the Book is the Book is not attached to any songs.
         """
         self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics,
             translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
@@ -350,7 +476,7 @@
 
     def onBookDeleteButtonClick(self):
         """
-        Delete the Book is the Book is not attached to any songs
+        Delete the Book is the Book is not attached to any songs.
         """
         self._deleteItem(Book, self.BooksListWidget, self.resetBooks,
             translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),

=== modified file 'openlp/plugins/songs/lib/db.py'
--- openlp/plugins/songs/lib/db.py	2010-06-12 02:14:18 +0000
+++ openlp/plugins/songs/lib/db.py	2010-07-17 16:08:42 +0000
@@ -58,6 +58,18 @@
     """
     pass
 
+class SongsTopics(BaseModel):
+    """
+    Songs topics model
+    """
+    pass
+    
+class AuthorsSongs(BaseModel):
+    """
+    Songs authors model
+    """
+    pass
+
 def init_schema(url):
     """
     Setup the songs database connection and initialise the database schema
@@ -146,6 +158,8 @@
             'topics': relation(Topic, backref='songs',
             secondary=songs_topics_table)})
     mapper(Topic, topics_table)
+    mapper(SongsTopics, songs_topics_table)
+    mapper(AuthorsSongs,  authors_songs_table)
 
     metadata.create_all(checkfirst=True)
     return session


Follow ups