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

Proposed by Tim Bentley
Status: Superseded
Proposed branch: lp:~trb143/openlp/bug-772523
Merge into: lp:openlp
Diff against target: 185 lines (+49/-13)
7 files modified
openlp/core/lib/db.py (+8/-1)
openlp/plugins/songs/forms/songexportform.py (+3/-0)
openlp/plugins/songs/lib/db.py (+2/-1)
openlp/plugins/songs/lib/mediaitem.py (+13/-3)
openlp/plugins/songs/lib/upgrade.py (+12/-1)
openlp/plugins/songs/lib/xml.py (+6/-7)
openlp/plugins/songs/songsplugin.py (+5/-0)
To merge this branch: bzr merge lp:~trb143/openlp/bug-772523
Reviewer Review Type Date Requested Status
Raoul Snyman Pending
Review via email: mp+84404@code.launchpad.net

This proposal supersedes a proposal from 2011-12-04.

This proposal has been superseded by a proposal from 2011-12-05.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

Well, first remove your print statement.

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

You will need to set the default of the new column, something like this:

110 Column(u'temporary', types.Boolean(), default=False)\
111 .create(table=tables[u'songs'])
        connection = metadata.bind.connect()
        update_statement = tables[u'songs'].update().values(temporary=False)
        connection.execute(update_statement)

lp:~trb143/openlp/bug-772523 updated
1772. By Tim Bentley

Fix up song import code

1773. By Tim Bentley

Head

1774. By Tim Bentley

Fixes

1775. By Tim Bentley

Head

1776. By Tim Bentley

Fixes and notifications

1777. By Tim Bentley

Lost temporary edit flag

1778. By Tim Bentley

clean up service

1779. By Tim Bentley

Head

1780. By Tim Bentley

Fix review comments

1781. By Tim Bentley

Fix review comments

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/lib/db.py'
2--- openlp/core/lib/db.py 2011-12-03 12:51:40 +0000
3+++ openlp/core/lib/db.py 2011-12-05 19:51:24 +0000
4@@ -358,10 +358,17 @@
5
6 def delete_all_objects(self, object_class, filter_clause=None):
7 """
8- Delete all object records
9+ Delete all object records.
10+ This method should only be used for simple tables and not ones with
11+ relationships. The relationships are not deleted from the database and
12+ this will lead to database corruptions.
13
14 ``object_class``
15 The type of object to delete
16+
17+ ``filter_clause``
18+ The filter governing selection of objects to return. Defaults to
19+ None.
20 """
21 try:
22 query = self.session.query(object_class)
23
24=== modified file 'openlp/plugins/songs/forms/songexportform.py'
25--- openlp/plugins/songs/forms/songexportform.py 2011-08-26 15:48:58 +0000
26+++ openlp/plugins/songs/forms/songexportform.py 2011-12-05 19:51:24 +0000
27@@ -252,6 +252,9 @@
28 songs = self.plugin.manager.get_all_objects(Song)
29 songs.sort(cmp=locale.strcoll, key=lambda song: song.title.lower())
30 for song in songs:
31+ # No need to export temporary songs.
32+ if song.temporary:
33+ continue
34 authors = u', '.join([author.display_name
35 for author in song.authors])
36 title = u'%s (%s)' % (unicode(song.title), authors)
37
38=== modified file 'openlp/plugins/songs/lib/db.py'
39--- openlp/plugins/songs/lib/db.py 2011-08-26 23:04:54 +0000
40+++ openlp/plugins/songs/lib/db.py 2011-12-05 19:51:24 +0000
41@@ -199,7 +199,8 @@
42 Column(u'search_lyrics', types.UnicodeText, nullable=False),
43 Column(u'create_date', types.DateTime(), default=func.now()),
44 Column(u'last_modified', types.DateTime(), default=func.now(),
45- onupdate=func.now())
46+ onupdate=func.now()),
47+ Column(u'temporary', types.Boolean(), default=False)
48 )
49
50 # Definition of the "topics" table
51
52=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
53--- openlp/plugins/songs/lib/mediaitem.py 2011-11-24 22:34:27 +0000
54+++ openlp/plugins/songs/lib/mediaitem.py 2011-12-05 19:51:24 +0000
55@@ -270,6 +270,9 @@
56 searchresults.sort(
57 cmp=locale.strcoll, key=lambda song: song.title.lower())
58 for song in searchresults:
59+ # Do not display temporary songs
60+ if song.temporary:
61+ continue
62 author_list = [author.display_name for author in song.authors]
63 song_title = unicode(song.title)
64 song_detail = u'%s (%s)' % (song_title, u', '.join(author_list))
65@@ -286,6 +289,9 @@
66 self.listView.clear()
67 for author in searchresults:
68 for song in author.songs:
69+ # Do not display temporary songs
70+ if song.temporary:
71+ continue
72 song_detail = u'%s (%s)' % (author.display_name, song.title)
73 song_name = QtGui.QListWidgetItem(song_detail)
74 song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
75@@ -552,16 +558,20 @@
76 # If there's any backing tracks, copy them over.
77 if len(item.background_audio) > 0:
78 self._updateBackgroundAudio(song, item)
79- if add_song and self.addSongFromService:
80+ if add_song:
81 song = self.openLyrics.xml_to_song(item.xml_version)
82 # If there's any backing tracks, copy them over.
83 if len(item.background_audio) > 0:
84 self._updateBackgroundAudio(song, item)
85 editId = song.id
86 self.onSearchTextButtonClick()
87- else:
88+ elif not self.addSongFromService:
89 # Make sure we temporary import formatting tags.
90- self.openLyrics.xml_to_song(item.xml_version, True)
91+ song = self.openLyrics.xml_to_song(item.xml_version, True)
92+ # If there's any backing tracks, copy them over.
93+ if len(item.background_audio) > 0:
94+ self._updateBackgroundAudio(song, item)
95+ editId = song.id
96 # Update service with correct song id.
97 if editId:
98 Receiver.send_message(u'service_item_update',
99
100=== modified file 'openlp/plugins/songs/lib/upgrade.py'
101--- openlp/plugins/songs/lib/upgrade.py 2011-12-02 20:17:57 +0000
102+++ openlp/plugins/songs/lib/upgrade.py 2011-12-05 19:51:24 +0000
103@@ -33,7 +33,9 @@
104 from sqlalchemy.sql.expression import func
105 from migrate.changeset.constraint import ForeignKeyConstraint
106
107-__version__ = 2
108+from openlp.plugins.songs.lib.db import Song
109+
110+__version__ = 3
111
112 def upgrade_setup(metadata):
113 """
114@@ -86,3 +88,12 @@
115 Column(u'last_modified', types.DateTime(), default=func.now())\
116 .create(table=tables[u'songs'])
117
118+def upgrade_3(session, metadata, tables):
119+ """
120+ Version 3 upgrade.
121+
122+ This upgrade adds a temporary song flag to the songs table
123+ """
124+ Column(u'temporary', types.Boolean(), default=False)\
125+ .create(table=tables[u'songs'])
126+
127
128=== modified file 'openlp/plugins/songs/lib/xml.py'
129--- openlp/plugins/songs/lib/xml.py 2011-10-09 19:51:44 +0000
130+++ openlp/plugins/songs/lib/xml.py 2011-12-05 19:51:24 +0000
131@@ -346,7 +346,7 @@
132 lines_element.set(u'break', u'optional')
133 return self._extract_xml(song_xml)
134
135- def xml_to_song(self, xml, parse_and_not_save=False):
136+ def xml_to_song(self, xml, parse_and_temporary_save=False):
137 """
138 Create and save a song from OpenLyrics format xml to the database. Since
139 we also export XML from external sources (e. g. OpenLyrics import), we
140@@ -355,9 +355,9 @@
141 ``xml``
142 The XML to parse (unicode).
143
144- ``parse_and_not_save``
145- Switch to skip processing the whole song and to prevent storing the
146- songs to the database. Defaults to ``False``.
147+ ``parse_and_temporary_save``
148+ Switch to skip processing the whole song and storing the songs in
149+ the database with a temporary flag. Defaults to ``False``.
150 """
151 # No xml get out of here.
152 if not xml:
153@@ -371,14 +371,13 @@
154 return None
155 # Formatting tags are new in OpenLyrics 0.8
156 if float(song_xml.get(u'version')) > 0.7:
157- self._process_formatting_tags(song_xml, parse_and_not_save)
158- if parse_and_not_save:
159- return
160+ self._process_formatting_tags(song_xml, parse_and_temporary_save)
161 song = Song()
162 # Values will be set when cleaning the song.
163 song.search_lyrics = u''
164 song.verse_order = u''
165 song.search_title = u''
166+ song.temporary = parse_and_temporary_save
167 self._process_copyright(properties, song)
168 self._process_cclinumber(properties, song)
169 self._process_titles(properties, song)
170
171=== modified file 'openlp/plugins/songs/songsplugin.py'
172--- openlp/plugins/songs/songsplugin.py 2011-12-03 13:32:19 +0000
173+++ openlp/plugins/songs/songsplugin.py 2011-12-05 19:51:24 +0000
174@@ -264,6 +264,11 @@
175 Time to tidy up on exit
176 """
177 log.info(u'Songs Finalising')
178+ # Remove temporary songs
179+ songs = self.manager.get_all_objects(Song, Song.temporary == True)
180+ for song in songs:
181+ self.manager.delete_object(Song, song.id)
182+ # Clean up files and connections
183 self.manager.finalise()
184 self.songImportItem.setVisible(False)
185 self.songExportItem.setVisible(False)