fixed duplicates in verse order when adding verses with the same tag.

fixed handling of part verses eg (1a, 1b, 1.5, etc) in SongShowPlus importer
This commit is contained in:
phill-ridout 2013-02-17 19:37:59 +00:00
parent 1b6a54c55d
commit ca2b2db640
3 changed files with 17 additions and 24 deletions

View File

@ -260,7 +260,8 @@ class SongImport(QtCore.QObject):
elif int(verse_def[1:]) > self.verseCounts[verse_def[0]]: elif int(verse_def[1:]) > self.verseCounts[verse_def[0]]:
self.verseCounts[verse_def[0]] = int(verse_def[1:]) self.verseCounts[verse_def[0]] = int(verse_def[1:])
self.verses.append([verse_def, verse_text.rstrip(), lang]) self.verses.append([verse_def, verse_text.rstrip(), lang])
self.verseOrderListGenerated.append(verse_def) if verse_def not in self.verseOrderListGenerated:
self.verseOrderListGenerated.append(verse_def)
def repeatVerse(self): def repeatVerse(self):
""" """

View File

@ -32,6 +32,7 @@ SongShow Plus songs into the OpenLP database.
""" """
import os import os
import logging import logging
import re
import struct import struct
from openlp.core.ui.wizard import WizardStrings from openlp.core.ui.wizard import WizardStrings
@ -44,13 +45,13 @@ COPYRIGHT = 3
CCLI_NO = 5 CCLI_NO = 5
VERSE = 12 VERSE = 12
CHORUS = 20 CHORUS = 20
BRIDGE = 24
TOPIC = 29 TOPIC = 29
COMMENTS = 30 COMMENTS = 30
VERSE_ORDER = 31 VERSE_ORDER = 31
SONG_BOOK = 35 SONG_BOOK = 35
SONG_NUMBER = 36 SONG_NUMBER = 36
CUSTOM_VERSE = 37 CUSTOM_VERSE = 37
BRIDGE = 24
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -183,13 +184,16 @@ class SongShowPlusImport(SongImport):
self.logError(file) self.logError(file)
def toOpenLPVerseTag(self, verse_name, ignore_unique=False): def toOpenLPVerseTag(self, verse_name, ignore_unique=False):
if verse_name.find(" ") != -1: # Have we got any digits? If so, verse number is everything from the digits to the end (OpenLP does not have
verse_parts = verse_name.split(" ") # concept of part verses, so just ignore any non integers on the end (including floats))
verse_type = verse_parts[0] match = re.match(u'(\D*)(\d+)', verse_name)
verse_number = verse_parts[1] if match is not None:
verse_type = match.group(1).strip()
verse_number = match.group(2)
else: else:
# otherwise we assume number 1 and take the whole prefix as the verse tag
verse_type = verse_name verse_type = verse_name
verse_number = "1" verse_number = u'1'
verse_type = verse_type.lower() verse_type = verse_type.lower()
if verse_type == "verse": if verse_type == "verse":
verse_tag = VerseType.Tags[VerseType.Verse] verse_tag = VerseType.Tags[VerseType.Verse]

View File

@ -12,28 +12,16 @@ TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..',
class TestSongShowPlusImport(TestCase): class TestSongShowPlusImport(TestCase):
def default_test(self): #test do import
""" # set self.import source to non list type. Do import should return None or False?
Test the defaults of songshowplusimport # set self.import source to a list of files
""" # importWizard.progressBar should be set to the number of files in the list
# Given: The songshowplusimport module as imported # set self.stop_import_flag to true. Do import should return None or False?
# When: Imported the module should have defaults set
constants = {u'TITLE' : 1, u'AUTHOR' : 2, u'COPYRIGHT' : 3, u'CCLI_NO' : 5, u'VERSE' : 12, u'CHORUS' : 20,
u'BRIDGE' : 24, u'TOPIC' : 29, u'COMMENTS' : 30, u'VERSE_ORDER' : 31, u'SONG_BOOK' : 35,
u'SONG_NUMBER' : 36, u'CUSTOM_VERSE' : 37, u'SongShowPlusImport.otherList' : {},
u'SongShowPlusImport.otherCount' : 0}
# Then: The constants should not have changed.
for constant in constants:
value = constants[constant]
self.assertEquals(eval(u'songshowplusimport.%s' % constant), value,
u'%s should be set as %s' % (constant, value))
def do_import_test(self): def do_import_test(self):
mocked_manager = MagicMock() mocked_manager = MagicMock()
songshowplusimport.SongImport = MagicMock()
with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport') as mocked_song_import: with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport') as mocked_song_import:
ssp_import_class = songshowplusimport.SongShowPlusImport(mocked_manager) ssp_import_class = songshowplusimport.SongShowPlusImport(mocked_manager)