forked from openlp/openlp
better solution
This commit is contained in:
parent
5bedf62ec4
commit
64b9b42321
@ -171,8 +171,7 @@ class VerseType(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_loose_input(verse_name):
|
def from_loose_input(verse_name):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given string, Other if not found. Use this
|
Return the VerseType for a given string, Other if not found
|
||||||
with caution!
|
|
||||||
|
|
||||||
``verse_name``
|
``verse_name``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
@ -266,23 +265,54 @@ def clean_song(manager, song):
|
|||||||
whitespace = re.compile(r'\W+', re.UNICODE)
|
whitespace = re.compile(r'\W+', re.UNICODE)
|
||||||
song.search_title = (whitespace.sub(u' ', song.title).strip() + u'@' +
|
song.search_title = (whitespace.sub(u' ', song.title).strip() + u'@' +
|
||||||
whitespace.sub(u' ', song.alternate_title).strip()).strip().lower()
|
whitespace.sub(u' ', song.alternate_title).strip()).strip().lower()
|
||||||
|
# Only do this, if we the song is a 1.9.4 song (or older).
|
||||||
|
if song.lyrics.find(u'<lyrics language="en">') != -1:
|
||||||
|
# Remove the old "language" attribute from lyrics tag (prior to 1.9.5).
|
||||||
|
# This is not very important, but this keeps the database clean. This
|
||||||
|
# can be removed when everybody has cleaned his songs.
|
||||||
|
song.lyrics = song.lyrics.replace(
|
||||||
|
u'<lyrics language="en">', u'<lyrics>')
|
||||||
verses = SongXML().get_verses(song.lyrics)
|
verses = SongXML().get_verses(song.lyrics)
|
||||||
lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses])
|
lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses])
|
||||||
song.search_lyrics = lyrics.lower()
|
song.search_lyrics = lyrics.lower()
|
||||||
|
# We need a new and clean SongXML instance.
|
||||||
|
sxml = SongXML()
|
||||||
|
# Rebuild the song's verses, to remove any wrong verse names (for
|
||||||
|
# example translated ones), which might have been added prior to 1.9.5.
|
||||||
|
# List for later comparison.
|
||||||
compare_order = []
|
compare_order = []
|
||||||
for verse in verses:
|
for verse in verses:
|
||||||
compare_order.append(
|
verse_type = VerseType.Tags[VerseType.from_loose_input(
|
||||||
(u'%s%s' % (verse[0][u'type'], verse[0][u'label'])).upper())
|
verse[0][u'type'])]
|
||||||
|
sxml.add_verse_to_lyrics(
|
||||||
|
verse_type,
|
||||||
|
verse[0][u'label'],
|
||||||
|
verse[1],
|
||||||
|
verse[0][u'lang'] if verse[0].has_key(u'lang') else None
|
||||||
|
)
|
||||||
|
compare_order.append((u'%s%s' % (verse_type, verse[0][u'label'])
|
||||||
|
).upper())
|
||||||
if verse[0][u'label'] == u'1':
|
if verse[0][u'label'] == u'1':
|
||||||
compare_order.append(verse[0][u'type'].upper())
|
compare_order.append(verse_type.upper())
|
||||||
# Check if the verse order contains tags for verses which do not exist.
|
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||||
# (This is relevant for people upgrading from 1.9.4 and older).
|
# Rebuild the verse order, to convert translated verse tags, which might
|
||||||
|
# have been added prior to 1.9.5.
|
||||||
if song.verse_order:
|
if song.verse_order:
|
||||||
order = song.verse_order.strip().split()
|
order = song.verse_order.strip().split()
|
||||||
else:
|
else:
|
||||||
order = []
|
order = []
|
||||||
for order in order:
|
new_order = []
|
||||||
# The verse order contains invalid tags, so reset the order.
|
for verse_def in order:
|
||||||
|
verse_type = VerseType.Tags[
|
||||||
|
VerseType.from_loose_input(verse_def[0])]
|
||||||
|
if len(verse_def) > 1:
|
||||||
|
new_order.append(
|
||||||
|
(u'%s%s' % (verse_type, verse_def[1:])).upper())
|
||||||
|
else:
|
||||||
|
new_order.append(verse_type.upper())
|
||||||
|
song.verse_order = u' '.join(new_order)
|
||||||
|
# Check if the verse order contains tags for verses which do not exist.
|
||||||
|
for order in new_order:
|
||||||
if order not in compare_order:
|
if order not in compare_order:
|
||||||
song.verse_order = u''
|
song.verse_order = u''
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user