Fix song service load (Bug #696219)

This commit is contained in:
Jon Tibble 2011-02-05 23:52:05 +00:00
parent d4e91ed553
commit a120719884

View File

@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui
from sqlalchemy.sql import or_ from sqlalchemy.sql import or_
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, Receiver, \ from openlp.core.lib import MediaManagerItem, BaseListWithDnD, Receiver, \
ItemCapabilities, translate, check_item_selected ItemCapabilities, translate, check_item_selected, PluginStatus
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
SongImportForm SongImportForm
from openlp.plugins.songs.lib import OpenLyrics, SongXML from openlp.plugins.songs.lib import OpenLyrics, SongXML
@ -396,46 +396,46 @@ class SongMediaItem(MediaManagerItem):
Triggered by a song being loaded by the service item Triggered by a song being loaded by the service item
""" """
log.debug(u'serviceLoad') log.debug(u'serviceLoad')
if item.data_string: if self.plugin.status != PluginStatus.Active or not item.data_string:
search_results = self.parent.manager.get_all_objects(Song, return
Song.search_title == re.compile(r'\W+', re.UNICODE).sub(u' ', search_results = self.parent.manager.get_all_objects(Song,
item.data_string[u'title'].split(u'@')[0].lower()).strip(), Song.search_title == re.compile(r'\W+', re.UNICODE).sub(u' ',
Song.search_title.asc()) item.data_string[u'title'].split(u'@')[0].lower()).strip(),
author_list = item.data_string[u'authors'].split(u', ') Song.search_title.asc())
# The service item always has an author (at least it has u'' as author_list = item.data_string[u'authors'].split(u', ')
# author). However, songs saved in the database do not have to have # The service item always has an author (at least it has u'' as
# an author. # author). However, songs saved in the database do not have to have
if u'' in author_list: # an author.
author_list.remove(u'') if u'' in author_list:
editId = 0 author_list.remove(u'')
add_song = True editId = 0
if search_results: add_song = True
for song in search_results: if search_results:
same_authors = True for song in search_results:
# If the author counts are different, we do not have to do same_authors = True
# any further checking. This is also important when a song # If the author counts are different, we do not have to do any
# does not have any author (because we can not loop over an # further checking. This is also important when a song does not
# empty list). # have any author (because we can not loop over an empty list).
if len(song.authors) == len(author_list): if len(song.authors) == len(author_list):
for author in song.authors: for author in song.authors:
if author.display_name not in author_list: if author.display_name not in author_list:
same_authors = False same_authors = False
else: else:
same_authors = False same_authors = False
# All authors are the same, so we can stop here and the song # All authors are the same, so we can stop here and the song
# does not have to be saved. # does not have to be saved.
if same_authors: if same_authors:
add_song = False add_song = False
editId = song.id editId = song.id
break break
if add_song: if add_song:
if self.addSongFromService: if self.addSongFromService:
editId = self.openLyrics.xml_to_song(item.xml_version) editId = self.openLyrics.xml_to_song(item.xml_version)
self.onSearchTextButtonClick() self.onSearchTextButtonClick()
# Update service with correct song id. # Update service with correct song id.
if editId: if editId:
Receiver.send_message(u'service_item_update', Receiver.send_message(u'service_item_update',
u'%s:%s' % (editId, item._uuid)) u'%s:%s' % (editId, item._uuid))
def collateSongTitles(self, song_1, song_2): def collateSongTitles(self, song_1, song_2):
""" """