openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #06503
[Merge] lp:~googol-hush/openlp/trivial into lp:openlp
Andreas Preikschat has proposed merging lp:~googol-hush/openlp/trivial into lp:openlp.
Requested reviews:
Raoul Snyman (raoul-snyman)
Tim Bentley (trb143)
Jon Tibble (meths)
For more details, see:
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/50994
Hello!
The re-index tool adds 'Author unknown' if songs do not have any author.
Cheers
--
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/50994
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/__init__.py'
--- openlp/plugins/songs/lib/__init__.py 2011-02-18 08:25:43 +0000
+++ openlp/plugins/songs/lib/__init__.py 2011-02-23 20:34:03 +0000
@@ -25,7 +25,10 @@
###############################################################################
from PyQt4 import QtGui
+
from openlp.core.lib import translate
+from db import Author
+from ui import SongStrings
class VerseType(object):
"""
@@ -241,6 +244,23 @@
return None
return filter(lambda item: item[1] == choice[0], encodings)[0][0]
+def add_author_unknown(manager, song):
+ """
+ Add the default author *Author Unknown* to the song.
+
+ ``manager``
+ The song's manager.
+
+ ``song``
+ The song object.
+ """
+ name = SongStrings.AuthorUnknown
+ author = 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)
+
from xml import OpenLyrics, SongXML
from songstab import SongsTab
from mediaitem import SongMediaItem
=== modified file 'openlp/plugins/songs/lib/olpimport.py'
--- openlp/plugins/songs/lib/olpimport.py 2011-02-18 17:34:43 +0000
+++ openlp/plugins/songs/lib/olpimport.py 2011-02-23 20:34:03 +0000
@@ -36,6 +36,7 @@
from openlp.core.lib import translate
from openlp.core.lib.db import BaseModel
+from openlp.plugins.songs.lib import add_author_unknown
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic #, MediaFile
from songimport import SongImport
@@ -47,30 +48,35 @@
"""
pass
+
class OldBook(BaseModel):
"""
Book model
"""
pass
+
class OldMediaFile(BaseModel):
"""
MediaFile model
"""
pass
+
class OldSong(BaseModel):
"""
Song model
"""
pass
+
class OldTopic(BaseModel):
"""
Topic model
"""
pass
+
class OpenLPSongImport(SongImport):
"""
The :class:`OpenLPSongImport` class provides OpenLP with the ability to
@@ -170,25 +176,18 @@
new_song.comments = song.comments
new_song.theme_name = song.theme_name
new_song.ccli_number = song.ccli_number
- if song.authors:
- for author in song.authors:
- existing_author = self.manager.get_object_filtered(
- Author, Author.display_name == author.display_name)
- if existing_author:
- new_song.authors.append(existing_author)
- else:
- new_song.authors.append(Author.populate(
- first_name=author.first_name,
- last_name=author.last_name,
- display_name=author.display_name))
- else:
- au = self.manager.get_object_filtered(Author,
- Author.display_name == u'Author Unknown')
- if au:
- new_song.authors.append(au)
+ for author in song.authors:
+ existing_author = self.manager.get_object_filtered(
+ Author, Author.display_name == author.display_name)
+ if existing_author:
+ new_song.authors.append(existing_author)
else:
new_song.authors.append(Author.populate(
- display_name=u'Author Unknown'))
+ first_name=author.first_name,
+ last_name=author.last_name,
+ display_name=author.display_name))
+ if not new_song.authors:
+ add_author_unknown(self.manager, new_song)
if song.book:
existing_song_book = self.manager.get_object_filtered(
Book, Book.name == song.book.name)
=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py 2011-02-20 00:05:50 +0000
+++ openlp/plugins/songs/lib/songimport.py 2011-02-23 20:34:03 +0000
@@ -29,7 +29,7 @@
from PyQt4 import QtCore
from openlp.core.lib import Receiver, translate
-from openlp.plugins.songs.lib import VerseType
+from openlp.plugins.songs.lib import add_author_unknown, VerseType
from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile
from openlp.plugins.songs.lib.ui import SongStrings
from openlp.plugins.songs.lib.xml import SongXML
@@ -270,8 +270,6 @@
"""
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)
song = Song()
song.title = self.title
@@ -315,10 +313,13 @@
author = self.manager.get_object_filtered(Author,
Author.display_name == authortext)
if not author:
- author = Author.populate(display_name = authortext,
+ author = Author.populate(display_name=authortext,
last_name=authortext.split(u' ')[-1],
first_name=u' '.join(authortext.split(u' ')[:-1]))
song.authors.append(author)
+ # No author, add the default author.
+ if not song.authors:
+ add_author_unknown(self.manager, song)
for filename in self.media_files:
media_file = self.manager.get_object_filtered(MediaFile,
MediaFile.file_name == filename)
=== modified file 'openlp/plugins/songs/lib/ui.py'
--- openlp/plugins/songs/lib/ui.py 2011-02-16 17:54:31 +0000
+++ openlp/plugins/songs/lib/ui.py 2011-02-23 20:34:03 +0000
@@ -36,8 +36,7 @@
# These strings should need a good reason to be retranslated elsewhere.
Author = translate('OpenLP.Ui', 'Author', 'Singular')
Authors = translate('OpenLP.Ui', 'Authors', 'Plural')
- AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used in the UI.
- AuthorUnknownUnT = u'Author Unknown' # Used to populate the database.
+ AuthorUnknown = u'Author Unknown' # Used to populate the database.
CopyrightSymbol = translate('OpenLP.Ui', '\xa9', 'Copyright symbol.')
SongBook = translate('OpenLP.Ui', 'Song Book', 'Singular')
SongBooks = translate('OpenLP.Ui', 'Song Books', 'Plural')
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2011-02-20 17:34:57 +0000
+++ openlp/plugins/songs/lib/xml.py 2011-02-23 20:34:03 +0000
@@ -66,7 +66,7 @@
from lxml import etree, objectify
-from openlp.plugins.songs.lib import VerseType
+from openlp.plugins.songs.lib import add_author_unknown, VerseType
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic
from openlp.plugins.songs.lib.ui import SongStrings
@@ -374,8 +374,6 @@
display_name = self._text(author)
if display_name:
authors.append(display_name)
- if not authors:
- authors.append(SongStrings.AuthorUnknownUnT)
for display_name in authors:
author = self.manager.get_object_filtered(Author,
Author.display_name == display_name)
@@ -384,8 +382,8 @@
author = Author.populate(display_name=display_name,
last_name=display_name.split(u' ')[-1],
first_name=u' '.join(display_name.split(u' ')[:-1]))
- self.manager.save_object(author)
- song.authors.append(author)
+ if not song.authors:
+ add_author_unknown(self.manager, song)
def _process_cclinumber(self, properties, song):
"""
=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py 2011-02-18 01:07:55 +0000
+++ openlp/plugins/songs/songsplugin.py 2011-02-23 20:34:03 +0000
@@ -32,7 +32,8 @@
from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.core.lib.db import Manager
from openlp.core.lib.ui import UiStrings
-from openlp.plugins.songs.lib import SongMediaItem, SongsTab, SongXML
+from openlp.plugins.songs.lib import add_author_unknown, SongMediaItem, \
+ SongsTab, SongXML
from openlp.plugins.songs.lib.db import init_schema, Song
from openlp.plugins.songs.lib.importer import SongFormat
@@ -145,6 +146,9 @@
counter = 0
for song in songs:
counter += 1
+ # The song does not have any author, add one.
+ if not song.authors:
+ add_author_unknown(self.manager, song)
if song.title is None:
song.title = u''
if song.alternate_title is None:
Follow ups