forked from openlp/openlp
Small EasiSlides refactor
This commit is contained in:
parent
7d3a87c040
commit
2d21d0163c
@ -81,44 +81,43 @@ class EasiSlidesImport(SongImport):
|
|||||||
|
|
||||||
def _parse_song(self, song):
|
def _parse_song(self, song):
|
||||||
self._success = True
|
self._success = True
|
||||||
self._add_title(song)
|
self._add_title(self.title, song.Title1, True)
|
||||||
self._add_alttitle(song)
|
self._add_alttitle(self.alternate_title, song.Title2)
|
||||||
self._add_number(song)
|
self._add_number(self.song_number, song.SongNumber)
|
||||||
|
if self.song_number = u'0':
|
||||||
|
self.song_number = u''
|
||||||
self._add_authors(song)
|
self._add_authors(song)
|
||||||
self._add_copyright(song)
|
self._add_copyright(song)
|
||||||
self._add_book(song)
|
self._add_book(self.song_book_name, song.BookReference)
|
||||||
self._parse_and_add_lyrics(song)
|
self._parse_and_add_lyrics(song)
|
||||||
return self._success
|
return self._success
|
||||||
|
|
||||||
def _add_title(self, song):
|
def _add_unicode_attribute(self, self_attribute, import_attribute,
|
||||||
try:
|
mandatory=False):
|
||||||
self.title = unicode(song.Title1).strip()
|
"""
|
||||||
except UnicodeDecodeError:
|
Add imported values to the song model converting them to unicode at the
|
||||||
log.exception(u'Unicode decode error while decoding Title1')
|
same time. If the unicode decode fails or a mandatory attribute is not
|
||||||
self._success = False
|
present _success is set to False so the importer can react
|
||||||
except AttributeError:
|
appropriately.
|
||||||
log.exception(u'no Title1')
|
|
||||||
self._success = False
|
|
||||||
|
|
||||||
def _add_alttitle(self, song):
|
``self_attribute``
|
||||||
try:
|
The attribute in the song model to populate.
|
||||||
self.alternate_title = unicode(song.Title2).strip()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
log.exception(u'Unicode decode error while decoding Title2')
|
|
||||||
self._success = False
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _add_number(self, song):
|
``import_attribute``
|
||||||
|
The imported value to convert to unicode and save to the song.
|
||||||
|
|
||||||
|
``mandatory``
|
||||||
|
Signals that this attribute must exist in a valid song.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
number = unicode(song.SongNumber)
|
self_attribute = unicode(import_attribute).strip()
|
||||||
if number != u'0':
|
|
||||||
self.song_number = number
|
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
log.exception(u'Unicode decode error while decoding SongNumber')
|
log.exception(u'UnicodeDecodeError decoding %s' % import_attribute)
|
||||||
self._success = False
|
self._success = False
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
log.exception(u'No attribute %s' % import_attribute)
|
||||||
|
if mandatory:
|
||||||
|
self._success = False
|
||||||
|
|
||||||
def _add_authors(self, song):
|
def _add_authors(self, song):
|
||||||
try:
|
try:
|
||||||
@ -158,15 +157,6 @@ class EasiSlidesImport(SongImport):
|
|||||||
pass
|
pass
|
||||||
self.add_copyright(u' '.join(copyright))
|
self.add_copyright(u' '.join(copyright))
|
||||||
|
|
||||||
def _add_book(self, song):
|
|
||||||
try:
|
|
||||||
self.song_book_name = unicode(song.BookReference).strip()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
log.exception(u'Unicode decode error while decoding BookReference')
|
|
||||||
self._success = False
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _parse_and_add_lyrics(self, song):
|
def _parse_and_add_lyrics(self, song):
|
||||||
try:
|
try:
|
||||||
lyrics = unicode(song.Contents).strip()
|
lyrics = unicode(song.Contents).strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user