continued clean up

This commit is contained in:
Andreas Preikschat 2011-03-15 18:52:42 +01:00
parent 88cfbf5d02
commit 01efe60822
5 changed files with 17 additions and 32 deletions

View File

@ -729,6 +729,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song.alternate_title = unicode(self.alternativeEdit.text())
self.song.copyright = unicode(self.copyrightEdit.text())
self.song.search_title = u''
self.song.search_lyrics = u''
self.song.comments = unicode(self.commentsEdit.toPlainText())
ordertext = unicode(self.verseOrderEdit.text())
order = []
@ -751,7 +752,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
else:
self.song.theme_name = None
self.processLyrics()
self.processTitle()
self.song.authors = []
for row in range(self.authorsListView.count()):
item = self.authorsListView.item(row)
@ -762,6 +762,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
item = self.topicsListView.item(row)
topicId = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.song.topics.append(self.manager.get_object(Topic, topicId))
clean_song(self.song)
self.manager.save_object(self.song)
if not preview:
self.song = None
@ -774,7 +775,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
log.debug(u'processLyrics')
try:
sxml = SongXML()
text = u''
multiple = []
for i in range(0, self.verseListWidget.rowCount()):
item = self.verseListWidget.item(i, 0)
@ -783,12 +783,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
verse_num = verseId[1:]
sxml.add_verse_to_lyrics(verse_tag, verse_num,
unicode(item.text()))
# FIXME
text = text + self.whitespace.sub(u' ',
unicode(self.verseListWidget.item(i, 0).text())) + u' '
if (verse_num > u'1') and (verse_tag not in multiple):
if verse_num > u'1' and verse_tag not in multiple:
multiple.append(verse_tag)
self.song.search_lyrics = text.lower()
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
for verse in multiple:
self.song.verse_order = re.sub(u'([' + verse.upper() +
@ -797,14 +793,3 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
except:
log.exception(u'Problem processing song Lyrics \n%s',
sxml.dump_xml())
def processTitle(self):
"""
Process the song title entered by the user to remove stray punctuation
characters.
"""
# This method must only be run after the self.song = Song() assignment.
log.debug(u'processTitle')
# FIXME
self.song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'',
unicode(self.song.search_title)).lower().strip()

View File

@ -257,15 +257,6 @@ def clean_song(manager, song):
``song``
The song object.
"""
# The song does not have any author, add one.
if not song.authors:
name = SongStrings.AuthorUnknown
author = manager.get_object_filtered(
Author, Author.display_name == name)
if author is None:
author = Author.populate(
display_name=name, last_name=u'', first_name=u'')
song.authors.append(author)
song.title = song.title.strip() if song.title else u''
if song.alternate_title is None:
song.alternate_title = u''
@ -281,6 +272,15 @@ def clean_song(manager, song):
verses = SongXML().get_verses(song.lyrics)
lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses])
song.search_lyrics = lyrics.lower()
# The song does not have any author, add one.
if not song.authors:
name = SongStrings.AuthorUnknown
author = manager.get_object_filtered(
Author, Author.display_name == name)
if author is None:
author = Author.populate(
display_name=name, last_name=u'', first_name=u'')
song.authors.append(author)
from xml import OpenLyrics, SongXML
from songstab import SongsTab

View File

@ -419,8 +419,7 @@ class SongMediaItem(MediaManagerItem):
if self.plugin.status != PluginStatus.Active or not item.data_string:
return
search_results = self.parent.manager.get_all_objects(Song,
Song.search_title == re.compile(r'\W+', re.UNICODE).sub(u' ',
item.data_string[u'title'].split(u'@')[0].lower()).strip(),
Song.search_title == item.data_string[u'title'],
Song.search_title.asc())
author_list = item.data_string[u'authors'].split(u', ')
# The service item always has an author (at least it has u'' as

View File

@ -302,6 +302,9 @@ class OpenLyrics(object):
else:
return None
song = Song()
# Values will be set when cleaning the song.
song.search_lyrics = u''
song.verse_order = u''
self._process_copyright(properties, song)
self._process_cclinumber(properties, song)
self._process_titles(properties, song)
@ -459,7 +462,6 @@ class OpenLyrics(object):
if self._get(verse, u'lang'):
lang = self._get(verse, u'lang')
sxml.add_verse_to_lyrics(verse_type, verse_number, text, lang)
song.search_lyrics = u''
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
# Process verse order
if hasattr(properties, u'verseOrder'):

View File

@ -234,8 +234,8 @@ class SongsPlugin(Plugin):
for sfile in os.listdir(db_dir):
if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'):
song_dbs.append(os.path.join(db_dir, sfile))
self.onToolsReindexItemTriggered()
if len(song_dbs) == 0:
self.onToolsReindexItemTriggered()
return
progress = QtGui.QProgressDialog(self.formparent)
progress.setWindowModality(QtCore.Qt.WindowModal)
@ -244,7 +244,6 @@ class SongsPlugin(Plugin):
progress.setRange(0, len(song_dbs))
progress.setMinimumDuration(0)
progress.forceShow()
self.onToolsReindexItemTriggered()
for idx, db in enumerate(song_dbs):
progress.setValue(idx)
Receiver.send_message(u'openlp_process_events')