forked from openlp/openlp
removed _get method
This commit is contained in:
parent
23733608ef
commit
0ab092e56e
@ -353,7 +353,7 @@ class OpenLyrics(object):
|
|||||||
self._process_cclinumber(properties, song)
|
self._process_cclinumber(properties, song)
|
||||||
self._process_titles(properties, song)
|
self._process_titles(properties, song)
|
||||||
# The verse order is processed with the lyrics!
|
# The verse order is processed with the lyrics!
|
||||||
self._process_lyrics(properties, song_xml.lyrics, song)
|
self._process_lyrics(properties, song_xml, song)
|
||||||
self._process_comments(properties, song)
|
self._process_comments(properties, song)
|
||||||
self._process_authors(properties, song)
|
self._process_authors(properties, song)
|
||||||
self._process_songbooks(properties, song)
|
self._process_songbooks(properties, song)
|
||||||
@ -379,20 +379,6 @@ class OpenLyrics(object):
|
|||||||
return etree.tostring(xml, encoding=u'UTF-8',
|
return etree.tostring(xml, encoding=u'UTF-8',
|
||||||
xml_declaration=True)
|
xml_declaration=True)
|
||||||
|
|
||||||
def _get(self, element, attribute):
|
|
||||||
"""
|
|
||||||
This returns the element's attribute as unicode string.
|
|
||||||
|
|
||||||
``element``
|
|
||||||
The element.
|
|
||||||
|
|
||||||
``attribute``
|
|
||||||
The element's attribute (unicode).
|
|
||||||
"""
|
|
||||||
if element.get(attribute) is not None:
|
|
||||||
return unicode(element.get(attribute))
|
|
||||||
return u''
|
|
||||||
|
|
||||||
def _text(self, element):
|
def _text(self, element):
|
||||||
"""
|
"""
|
||||||
This returns the text of an element as unicode string.
|
This returns the text of an element as unicode string.
|
||||||
@ -474,22 +460,23 @@ class OpenLyrics(object):
|
|||||||
if hasattr(properties, u'copyright'):
|
if hasattr(properties, u'copyright'):
|
||||||
song.copyright = self._text(properties.copyright)
|
song.copyright = self._text(properties.copyright)
|
||||||
|
|
||||||
def _process_lyrics(self, properties, lyrics, song):
|
def _process_lyrics(self, properties, song_xml, song_obj):
|
||||||
"""
|
"""
|
||||||
Processes the verses and search_lyrics for the song.
|
Processes the verses and search_lyrics for the song.
|
||||||
|
|
||||||
``properties``
|
``properties``
|
||||||
The properties object (lxml.objectify.ObjectifiedElement).
|
The properties object (lxml.objectify.ObjectifiedElement).
|
||||||
|
|
||||||
``lyrics``
|
``song_xml``
|
||||||
The lyrics object (lxml.objectify.ObjectifiedElement).
|
The objectified song (lxml.objectify.ObjectifiedElement).
|
||||||
|
|
||||||
``song``
|
``song_obj``
|
||||||
The song object.
|
The song object.
|
||||||
"""
|
"""
|
||||||
sxml = SongXML()
|
sxml = SongXML()
|
||||||
verses = {}
|
verses = {}
|
||||||
verse_def_list = []
|
verse_def_list = []
|
||||||
|
lyrics = song_xml.lyrics
|
||||||
for verse in lyrics.verse:
|
for verse in lyrics.verse:
|
||||||
text = u''
|
text = u''
|
||||||
for lines in verse.lines:
|
for lines in verse.lines:
|
||||||
@ -497,9 +484,9 @@ class OpenLyrics(object):
|
|||||||
text += u'\n'
|
text += u'\n'
|
||||||
text += u'\n'.join(map(unicode, lines.line))
|
text += u'\n'.join(map(unicode, lines.line))
|
||||||
# Adgetd a virtual split to the verse text.
|
# Adgetd a virtual split to the verse text.
|
||||||
if self._get(lines, u'break'):
|
if lines.get(u'break') is not None:
|
||||||
text += u'\n[---]'
|
text += u'\n[---]'
|
||||||
verse_def = self._get(verse, u'name').lower()
|
verse_def = verse.get(u'name', u' ').lower()
|
||||||
if verse_def[0] in VerseType.Tags:
|
if verse_def[0] in VerseType.Tags:
|
||||||
verse_tag = verse_def[0]
|
verse_tag = verse_def[0]
|
||||||
else:
|
else:
|
||||||
@ -509,9 +496,7 @@ class OpenLyrics(object):
|
|||||||
# not correct the verse order.
|
# not correct the verse order.
|
||||||
if not verse_number:
|
if not verse_number:
|
||||||
verse_number = u'1'
|
verse_number = u'1'
|
||||||
lang = None
|
lang = verse.get(u'lang')
|
||||||
if self._get(verse, u'lang'):
|
|
||||||
lang = self._get(verse, u'lang')
|
|
||||||
if verses.has_key((verse_tag, verse_number, lang)):
|
if verses.has_key((verse_tag, verse_number, lang)):
|
||||||
verses[(verse_tag, verse_number, lang)] += u'\n[---]\n' + text
|
verses[(verse_tag, verse_number, lang)] += u'\n[---]\n' + text
|
||||||
else:
|
else:
|
||||||
@ -540,7 +525,7 @@ class OpenLyrics(object):
|
|||||||
song.song_number = u''
|
song.song_number = u''
|
||||||
if hasattr(properties, u'songbooks'):
|
if hasattr(properties, u'songbooks'):
|
||||||
for songbook in properties.songbooks.songbook:
|
for songbook in properties.songbooks.songbook:
|
||||||
bookname = self._get(songbook, u'name')
|
bookname = songbook.get(u'name', u'')
|
||||||
if bookname:
|
if bookname:
|
||||||
book = self.manager.get_object_filtered(Book,
|
book = self.manager.get_object_filtered(Book,
|
||||||
Book.name == bookname)
|
Book.name == bookname)
|
||||||
@ -549,7 +534,7 @@ class OpenLyrics(object):
|
|||||||
book = Book.populate(name=bookname, publisher=u'')
|
book = Book.populate(name=bookname, publisher=u'')
|
||||||
self.manager.save_object(book)
|
self.manager.save_object(book)
|
||||||
song.song_book_id = book.id
|
song.song_book_id = book.id
|
||||||
song.song_number = self._get(songbook, u'entry')
|
song.song_number = songbook.get(u'entry', u'')
|
||||||
# We only support one song book, so take the first one.
|
# We only support one song book, so take the first one.
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user