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: 177 lines (+48/-12)
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 (+12/-2)
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 Needs Information
Review via email: mp+84524@code.launchpad.net

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

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

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.

Amended code to add songs as per my email.

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 : Posted in a previous version of this proposal

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)

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

Are you going to add the setting of the default value of the new column?

review: Needs Information
lp:~trb143/openlp/bug-772523 updated
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-08 20: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-08 20: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-08 20: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-08 20: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@@ -559,9 +565,13 @@
76 self._updateBackgroundAudio(song, item)
77 editId = song.id
78 self.onSearchTextButtonClick()
79- else:
80+ elif not self.addSongFromService:
81 # Make sure we temporary import formatting tags.
82- self.openLyrics.xml_to_song(item.xml_version, True)
83+ song = self.openLyrics.xml_to_song(item.xml_version, True)
84+ # If there's any backing tracks, copy them over.
85+ if len(item.background_audio) > 0:
86+ self._updateBackgroundAudio(song, item)
87+ editId = song.id
88 # Update service with correct song id.
89 if editId:
90 Receiver.send_message(u'service_item_update',
91
92=== modified file 'openlp/plugins/songs/lib/upgrade.py'
93--- openlp/plugins/songs/lib/upgrade.py 2011-12-02 20:17:57 +0000
94+++ openlp/plugins/songs/lib/upgrade.py 2011-12-08 20:51:24 +0000
95@@ -33,7 +33,9 @@
96 from sqlalchemy.sql.expression import func
97 from migrate.changeset.constraint import ForeignKeyConstraint
98
99-__version__ = 2
100+from openlp.plugins.songs.lib.db import Song
101+
102+__version__ = 3
103
104 def upgrade_setup(metadata):
105 """
106@@ -86,3 +88,12 @@
107 Column(u'last_modified', types.DateTime(), default=func.now())\
108 .create(table=tables[u'songs'])
109
110+def upgrade_3(session, metadata, tables):
111+ """
112+ Version 3 upgrade.
113+
114+ This upgrade adds a temporary song flag to the songs table
115+ """
116+ Column(u'temporary', types.Boolean(), default=False)\
117+ .create(table=tables[u'songs'])
118+
119
120=== modified file 'openlp/plugins/songs/lib/xml.py'
121--- openlp/plugins/songs/lib/xml.py 2011-10-09 19:51:44 +0000
122+++ openlp/plugins/songs/lib/xml.py 2011-12-08 20:51:24 +0000
123@@ -346,7 +346,7 @@
124 lines_element.set(u'break', u'optional')
125 return self._extract_xml(song_xml)
126
127- def xml_to_song(self, xml, parse_and_not_save=False):
128+ def xml_to_song(self, xml, parse_and_temporary_save=False):
129 """
130 Create and save a song from OpenLyrics format xml to the database. Since
131 we also export XML from external sources (e. g. OpenLyrics import), we
132@@ -355,9 +355,9 @@
133 ``xml``
134 The XML to parse (unicode).
135
136- ``parse_and_not_save``
137- Switch to skip processing the whole song and to prevent storing the
138- songs to the database. Defaults to ``False``.
139+ ``parse_and_temporary_save``
140+ Switch to skip processing the whole song and storing the songs in
141+ the database with a temporary flag. Defaults to ``False``.
142 """
143 # No xml get out of here.
144 if not xml:
145@@ -371,14 +371,13 @@
146 return None
147 # Formatting tags are new in OpenLyrics 0.8
148 if float(song_xml.get(u'version')) > 0.7:
149- self._process_formatting_tags(song_xml, parse_and_not_save)
150- if parse_and_not_save:
151- return
152+ self._process_formatting_tags(song_xml, parse_and_temporary_save)
153 song = Song()
154 # Values will be set when cleaning the song.
155 song.search_lyrics = u''
156 song.verse_order = u''
157 song.search_title = u''
158+ song.temporary = parse_and_temporary_save
159 self._process_copyright(properties, song)
160 self._process_cclinumber(properties, song)
161 self._process_titles(properties, song)
162
163=== modified file 'openlp/plugins/songs/songsplugin.py'
164--- openlp/plugins/songs/songsplugin.py 2011-12-03 13:32:19 +0000
165+++ openlp/plugins/songs/songsplugin.py 2011-12-08 20:51:24 +0000
166@@ -264,6 +264,11 @@
167 Time to tidy up on exit
168 """
169 log.info(u'Songs Finalising')
170+ # Remove temporary songs
171+ songs = self.manager.get_all_objects(Song, Song.temporary == True)
172+ for song in songs:
173+ self.manager.delete_object(Song, song.id)
174+ # Clean up files and connections
175 self.manager.finalise()
176 self.songImportItem.setVisible(False)
177 self.songExportItem.setVisible(False)