← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/bug-772523 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/bug-772523 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~trb143/openlp/bug-772523/+merge/84384

NEED HELP Not a merge at present.

This patch changes your song database so back it up!

When a service is imported at present and we do not wish to save the songs we do not.  This prevents the user from editing songs.
This change adds a "temporary" flag on the song database to allow those songs to be save and edited bit not via the plugin as the search will not show them.
On exit the songs will be deleted.

The code works until a service is loaded and then you get sqlalchemy errors. 
I have no idea what is wrong but some help would be appreciated.

http://pastebin.com/fKF2m0nX  is a stack trace.
-- 
https://code.launchpad.net/~trb143/openlp/bug-772523/+merge/84384
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/bug-772523 into lp:openlp.
=== modified file 'openlp/core/lib/db.py'
--- openlp/core/lib/db.py	2011-12-03 12:51:40 +0000
+++ openlp/core/lib/db.py	2011-12-03 19:33:26 +0000
@@ -203,6 +203,7 @@
         if upgrade_mod:
             db_ver, up_ver = upgrade_db(self.db_url, upgrade_mod)
             if db_ver > up_ver:
+                print "hello"
                 critical_error_message_box(
                     translate('OpenLP.Manager', 'Database Error'),
                     unicode(translate('OpenLP.Manager', 'The database being '
@@ -362,6 +363,10 @@
 
         ``object_class``
             The type of object to delete
+
+        ``filter_clause``
+            The filter governing selection of objects to return. Defaults to
+            None.
         """
         try:
             query = self.session.query(object_class)

=== modified file 'openlp/plugins/songs/lib/db.py'
--- openlp/plugins/songs/lib/db.py	2011-08-26 23:04:54 +0000
+++ openlp/plugins/songs/lib/db.py	2011-12-03 19:33:26 +0000
@@ -199,7 +199,8 @@
         Column(u'search_lyrics', types.UnicodeText, nullable=False),
         Column(u'create_date', types.DateTime(), default=func.now()),
         Column(u'last_modified', types.DateTime(), default=func.now(),
-            onupdate=func.now())
+            onupdate=func.now()),
+        Column(u'temporary', types.Boolean(), default=False)
     )
 
     # Definition of the "topics" table

=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2011-11-24 22:34:27 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2011-12-03 19:33:26 +0000
@@ -270,6 +270,9 @@
         searchresults.sort(
             cmp=locale.strcoll, key=lambda song: song.title.lower())
         for song in searchresults:
+            # Do not display temporary songs
+            if song.temporary:
+                continue
             author_list = [author.display_name for author in song.authors]
             song_title = unicode(song.title)
             song_detail = u'%s (%s)' % (song_title, u', '.join(author_list))
@@ -286,6 +289,9 @@
         self.listView.clear()
         for author in searchresults:
             for song in author.songs:
+                # Do not display temporary songs
+                if song.temporary:
+                    continue
                 song_detail = u'%s (%s)' % (author.display_name, song.title)
                 song_name = QtGui.QListWidgetItem(song_detail)
                 song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
@@ -561,7 +567,8 @@
             self.onSearchTextButtonClick()
         else:
             # Make sure we temporary import formatting tags.
-            self.openLyrics.xml_to_song(item.xml_version, True)
+            song = self.openLyrics.xml_to_song(item.xml_version, True)
+            editId = song.id
         # Update service with correct song id.
         if editId:
             Receiver.send_message(u'service_item_update',

=== modified file 'openlp/plugins/songs/lib/upgrade.py'
--- openlp/plugins/songs/lib/upgrade.py	2011-12-02 20:17:57 +0000
+++ openlp/plugins/songs/lib/upgrade.py	2011-12-03 19:33:26 +0000
@@ -33,7 +33,9 @@
 from sqlalchemy.sql.expression import func
 from migrate.changeset.constraint import ForeignKeyConstraint
 
-__version__ = 2
+from openlp.plugins.songs.lib.db import Song
+
+__version__ = 3
 
 def upgrade_setup(metadata):
     """
@@ -86,3 +88,12 @@
     Column(u'last_modified', types.DateTime(), default=func.now())\
         .create(table=tables[u'songs'])
 
+def upgrade_3(session, metadata, tables):
+    """
+    Version 3 upgrade.
+
+    This upgrade adds a temporary song flag to the songs table
+    """
+    Column(u'temporary', types.Boolean(), default=False)\
+        .create(table=tables[u'songs'])
+

=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py	2011-10-09 19:51:44 +0000
+++ openlp/plugins/songs/lib/xml.py	2011-12-03 19:33:26 +0000
@@ -372,13 +372,13 @@
         # Formatting tags are new in OpenLyrics 0.8
         if float(song_xml.get(u'version')) > 0.7:
             self._process_formatting_tags(song_xml, parse_and_not_save)
-        if parse_and_not_save:
-            return
         song = Song()
         # Values will be set when cleaning the song.
         song.search_lyrics = u''
         song.verse_order = u''
         song.search_title = u''
+        if parse_and_not_save:
+            song.temporary = True
         self._process_copyright(properties, song)
         self._process_cclinumber(properties, song)
         self._process_titles(properties, song)

=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py	2011-12-03 13:32:19 +0000
+++ openlp/plugins/songs/songsplugin.py	2011-12-03 19:33:26 +0000
@@ -264,6 +264,9 @@
         Time to tidy up on exit
         """
         log.info(u'Songs Finalising')
+        # Remove temporary songs
+        self.manager.delete_all_objects(Song, Song.temporary == True)
+        # Clean up files and connections
         self.manager.finalise()
         self.songImportItem.setVisible(False)
         self.songExportItem.setVisible(False)


Follow ups