moved code

This commit is contained in:
Andreas Preikschat 2011-02-23 21:22:29 +01:00
parent de584a8945
commit 1eea1c97a4
5 changed files with 45 additions and 44 deletions

View File

@ -25,7 +25,10 @@
############################################################################### ###############################################################################
from PyQt4 import QtGui from PyQt4 import QtGui
from openlp.core.lib import translate from openlp.core.lib import translate
from db import Author
from ui import SongStrings
class VerseType(object): class VerseType(object):
""" """
@ -241,6 +244,24 @@ def retrieve_windows_encoding(recommendation=None):
return None return None
return filter(lambda item: item[1] == choice[0], encodings)[0][0] 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 xml import OpenLyrics, SongXML
from songstab import SongsTab from songstab import SongsTab
from mediaitem import SongMediaItem from mediaitem import SongMediaItem

View File

@ -36,6 +36,7 @@ from sqlalchemy.orm.exc import UnmappedClassError
from openlp.core.lib import translate from openlp.core.lib import translate
from openlp.core.lib.db import BaseModel 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 openlp.plugins.songs.lib.db import Author, Book, Song, Topic #, MediaFile
from songimport import SongImport from songimport import SongImport
@ -47,30 +48,35 @@ class OldAuthor(BaseModel):
""" """
pass pass
class OldBook(BaseModel): class OldBook(BaseModel):
""" """
Book model Book model
""" """
pass pass
class OldMediaFile(BaseModel): class OldMediaFile(BaseModel):
""" """
MediaFile model MediaFile model
""" """
pass pass
class OldSong(BaseModel): class OldSong(BaseModel):
""" """
Song model Song model
""" """
pass pass
class OldTopic(BaseModel): class OldTopic(BaseModel):
""" """
Topic model Topic model
""" """
pass pass
class OpenLPSongImport(SongImport): class OpenLPSongImport(SongImport):
""" """
The :class:`OpenLPSongImport` class provides OpenLP with the ability to The :class:`OpenLPSongImport` class provides OpenLP with the ability to
@ -170,7 +176,6 @@ class OpenLPSongImport(SongImport):
new_song.comments = song.comments new_song.comments = song.comments
new_song.theme_name = song.theme_name new_song.theme_name = song.theme_name
new_song.ccli_number = song.ccli_number new_song.ccli_number = song.ccli_number
if song.authors:
for author in song.authors: for author in song.authors:
existing_author = self.manager.get_object_filtered( existing_author = self.manager.get_object_filtered(
Author, Author.display_name == author.display_name) Author, Author.display_name == author.display_name)
@ -181,14 +186,8 @@ class OpenLPSongImport(SongImport):
first_name=author.first_name, first_name=author.first_name,
last_name=author.last_name, last_name=author.last_name,
display_name=author.display_name)) display_name=author.display_name))
else: if not new_song.authors:
au = self.manager.get_object_filtered(Author, add_author_unknown(self.manager, new_song)
Author.display_name == u'Author Unknown')
if au:
new_song.authors.append(au)
else:
new_song.authors.append(Author.populate(
display_name=u'Author Unknown'))
if song.book: if song.book:
existing_song_book = self.manager.get_object_filtered( existing_song_book = self.manager.get_object_filtered(
Book, Book.name == song.book.name) Book, Book.name == song.book.name)

View File

@ -29,7 +29,7 @@ import re
from PyQt4 import QtCore from PyQt4 import QtCore
from openlp.core.lib import Receiver, translate 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.db import Song, Author, Topic, Book, MediaFile
from openlp.plugins.songs.lib.ui import SongStrings from openlp.plugins.songs.lib.ui import SongStrings
from openlp.plugins.songs.lib.xml import SongXML from openlp.plugins.songs.lib.xml import SongXML
@ -319,13 +319,7 @@ class SongImport(QtCore.QObject):
song.authors.append(author) song.authors.append(author)
# No author, add the default author. # No author, add the default author.
if not song.authors: if not song.authors:
name = SongStrings.AuthorUnknown add_author_unknown(self.manager, song)
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

@ -66,7 +66,7 @@ import re
from lxml import etree, objectify 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.db import Author, Book, Song, Topic
from openlp.plugins.songs.lib.ui import SongStrings from openlp.plugins.songs.lib.ui import SongStrings
@ -382,15 +382,8 @@ 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]))
# The song does not have an author, add a default author.
if not song.authors: if not song.authors:
name = SongStrings.AuthorUnknown add_author_unknown(self.manager, song)
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)
def _process_cclinumber(self, properties, song): def _process_cclinumber(self, properties, song):
""" """

View File

@ -32,10 +32,10 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.core.lib.db import Manager from openlp.core.lib.db import Manager
from openlp.core.lib.ui import UiStrings 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, \
from openlp.plugins.songs.lib.db import Author, init_schema, Song SongsTab, SongXML
from openlp.plugins.songs.lib.db import init_schema, Song
from openlp.plugins.songs.lib.importer import SongFormat from openlp.plugins.songs.lib.importer import SongFormat
from openlp.plugins.songs.lib.ui import SongStrings
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -148,13 +148,7 @@ 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 = SongStrings.AuthorUnknown add_author_unknown(self.manager, song)
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)
if song.title is None: if song.title is None:
song.title = u'' song.title = u''
if song.alternate_title is None: if song.alternate_title is None: