Merge branch 'issue-937-handle-unknown-verse-types' into 'master'

Fix issue #937 by handling custom verse types correctly

Closes #937

See merge request openlp/openlp!396
This commit is contained in:
Tim Bentley 2022-02-03 07:49:14 +00:00
commit de30cc3996
2 changed files with 10 additions and 2 deletions

View File

@ -243,7 +243,12 @@ class SongSelectImport(object):
verse_type = verse['label'] verse_type = verse['label']
verse_number = 1 verse_number = 1
verse_type = VerseType.from_loose_input(verse_type) verse_type = VerseType.from_loose_input(verse_type)
verse_number = int(verse_number) try:
verse_number = int(verse_number)
except ValueError:
# Some custom verse types contain multiple words, and this messes with the verse number,
# so just default to 1 on ValueError. See https://gitlab.com/openlp/openlp/-/issues/937
verse_number = 1
song_xml.add_verse_to_lyrics(VerseType.tags[verse_type], verse_number, verse['lyrics']) song_xml.add_verse_to_lyrics(VerseType.tags[verse_type], verse_number, verse['lyrics'])
verse_order.append('{tag}{number}'.format(tag=VerseType.tags[verse_type], number=verse_number)) verse_order.append('{tag}{number}'.format(tag=VerseType.tags[verse_type], number=verse_number))
db_song.verse_order = ' '.join(verse_order) db_song.verse_order = ' '.join(verse_order)

View File

@ -374,6 +374,8 @@ class TestSongSelectImport(TestCase, TestMixin):
<p>verse thing 1<br>line 2</p> <p>verse thing 1<br>line 2</p>
<h3>Verse 2</h3> <h3>Verse 2</h3>
<p>verse thing 2</p> <p>verse thing 2</p>
<h3>Spoken Words</h3>
<p>completely custom verse type</p>
</div> </div>
<ul class="copyright"> <ul class="copyright">
<li>Copy thing</li><li>Copy thing 2</li> <li>Copy thing</li><li>Copy thing 2</li>
@ -396,7 +398,8 @@ class TestSongSelectImport(TestCase, TestMixin):
assert result['topics'] == ['theme1', 'theme2'] assert result['topics'] == ['theme1', 'theme2']
assert result['ccli_number'] == '1234_cclinumber_5678' assert result['ccli_number'] == '1234_cclinumber_5678'
assert result['verses'] == [{'label': 'Verse 1', 'lyrics': 'verse thing 1\nline 2'}, assert result['verses'] == [{'label': 'Verse 1', 'lyrics': 'verse thing 1\nline 2'},
{'label': 'Verse 2', 'lyrics': 'verse thing 2'}] {'label': 'Verse 2', 'lyrics': 'verse thing 2'},
{'label': 'Spoken Words', 'lyrics': 'completely custom verse type'}]
@patch('openlp.plugins.songs.lib.songselect.clean_song') @patch('openlp.plugins.songs.lib.songselect.clean_song')
@patch('openlp.plugins.songs.lib.songselect.Topic') @patch('openlp.plugins.songs.lib.songselect.Topic')