reworked author unknown

This commit is contained in:
Andreas Preikschat 2011-02-23 18:35:27 +01:00
parent 1e2e1ebdec
commit de584a8945
4 changed files with 21 additions and 11 deletions

View File

@ -270,8 +270,6 @@ class SongImport(QtCore.QObject):
""" """
All fields have been set to this song. Write the song to disk. All fields have been set to this song. Write the song to disk.
""" """
if not self.authors:
self.authors.append(SongStrings.AuthorUnknownUnT)
log.info(u'committing song %s to database', self.title) log.info(u'committing song %s to database', self.title)
song = Song() song = Song()
song.title = self.title song.title = self.title
@ -315,10 +313,19 @@ class SongImport(QtCore.QObject):
author = self.manager.get_object_filtered(Author, author = self.manager.get_object_filtered(Author,
Author.display_name == authortext) Author.display_name == authortext)
if not author: if not author:
author = Author.populate(display_name = authortext, author = Author.populate(display_name=authortext,
last_name=authortext.split(u' ')[-1], last_name=authortext.split(u' ')[-1],
first_name=u' '.join(authortext.split(u' ')[:-1])) first_name=u' '.join(authortext.split(u' ')[:-1]))
song.authors.append(author) song.authors.append(author)
# No author, add the default author.
if not song.authors:
name = SongStrings.AuthorUnknown
author = self.manager.get_object_filtered(
Author, Author.display_name == name)
if not author:
author = Author.populate(
display_name=name, last_name=u'', first_name=u'')
song.authors.append(author)
for filename in self.media_files: for filename in self.media_files:
media_file = self.manager.get_object_filtered(MediaFile, media_file = self.manager.get_object_filtered(MediaFile,
MediaFile.file_name == filename) MediaFile.file_name == filename)

View File

@ -36,8 +36,7 @@ class SongStrings(object):
# These strings should need a good reason to be retranslated elsewhere. # These strings should need a good reason to be retranslated elsewhere.
Author = translate('OpenLP.Ui', 'Author', 'Singular') Author = translate('OpenLP.Ui', 'Author', 'Singular')
Authors = translate('OpenLP.Ui', 'Authors', 'Plural') Authors = translate('OpenLP.Ui', 'Authors', 'Plural')
AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used in the UI. AuthorUnknown = u'Author Unknown' # Used to populate the database.
AuthorUnknownUnT = u'Author Unknown' # Used to populate the database.
CopyrightSymbol = translate('OpenLP.Ui', '\xa9', 'Copyright symbol.') CopyrightSymbol = translate('OpenLP.Ui', '\xa9', 'Copyright symbol.')
SongBook = translate('OpenLP.Ui', 'Song Book', 'Singular') SongBook = translate('OpenLP.Ui', 'Song Book', 'Singular')
SongBooks = translate('OpenLP.Ui', 'Song Books', 'Plural') SongBooks = translate('OpenLP.Ui', 'Song Books', 'Plural')

View File

@ -374,8 +374,6 @@ class OpenLyrics(object):
display_name = self._text(author) display_name = self._text(author)
if display_name: if display_name:
authors.append(display_name) authors.append(display_name)
if not authors:
authors.append(SongStrings.AuthorUnknownUnT)
for display_name in authors: for display_name in authors:
author = self.manager.get_object_filtered(Author, author = self.manager.get_object_filtered(Author,
Author.display_name == display_name) Author.display_name == display_name)
@ -384,7 +382,14 @@ class OpenLyrics(object):
author = Author.populate(display_name=display_name, author = Author.populate(display_name=display_name,
last_name=display_name.split(u' ')[-1], last_name=display_name.split(u' ')[-1],
first_name=u' '.join(display_name.split(u' ')[:-1])) first_name=u' '.join(display_name.split(u' ')[:-1]))
self.manager.save_object(author) # The song does not have an author, add a default author.
if not song.authors:
name = SongStrings.AuthorUnknown
author = self.manager.get_object_filtered(
Author, Author.display_name == name)
if author is None:
author = Author.populate(
display_name=name, last_name=u'', first_name=u'')
song.authors.append(author) song.authors.append(author)
def _process_cclinumber(self, properties, song): def _process_cclinumber(self, properties, song):

View File

@ -148,13 +148,12 @@ class SongsPlugin(Plugin):
counter += 1 counter += 1
# The song does not have any author, add one. # The song does not have any author, add one.
if not song.authors: if not song.authors:
name = unicode(SongStrings.AuthorUnknownUnT) name = SongStrings.AuthorUnknown
author = self.manager.get_object_filtered(Author, author = self.manager.get_object_filtered(Author,
Author.display_name == name) Author.display_name == name)
if author is None: if author is None:
author = Author.populate( author = Author.populate(
first_name=u' '.join(name.split(u' ', 1)[:-1]), display_name=name, last_name=u'', first_name=u'')
last_name=name.split(u' ', 1)[-1], display_name=name)
song.authors.append(author) song.authors.append(author)
if song.title is None: if song.title is None:
song.title = u'' song.title = u''