Put Author types in an own enum class

This commit is contained in:
Samuel Mehrbrodt 2014-03-30 19:23:36 +02:00
parent 69c32d91a4
commit 87051a094a
3 changed files with 26 additions and 22 deletions

View File

@ -42,7 +42,7 @@ from openlp.core.common import Registry, RegistryProperties, AppLocation, UiStri
from openlp.core.lib import FileDialog, PluginStatus, MediaType, create_separated_list from openlp.core.lib import FileDialog, PluginStatus, MediaType, create_separated_list
from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box
from openlp.plugins.songs.lib import VerseType, clean_song from openlp.plugins.songs.lib import VerseType, clean_song
from openlp.plugins.songs.lib.db import Book, Song, Author, AuthorSong, Topic, MediaFile from openlp.plugins.songs.lib.db import Book, Song, Author, AuthorSong, AuthorType, Topic, 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
from openlp.plugins.songs.forms.editsongdialog import Ui_EditSongDialog from openlp.plugins.songs.forms.editsongdialog import Ui_EditSongDialog
@ -306,9 +306,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties):
self.author_types_combo_box.clear() self.author_types_combo_box.clear()
self.author_types_combo_box.addItem('') self.author_types_combo_box.addItem('')
# Don't iterate over the dictionary to give them this specific order # Don't iterate over the dictionary to give them this specific order
self.author_types_combo_box.addItem(Author.Types[Author.TYPE_WORDS], Author.TYPE_WORDS) self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.Words], AuthorType.Words)
self.author_types_combo_box.addItem(Author.Types[Author.TYPE_MUSIC], Author.TYPE_MUSIC) self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.Music], AuthorType.Music)
self.author_types_combo_box.addItem(Author.Types[Author.TYPE_TRANSLATION], Author.TYPE_TRANSLATION) self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.Translation], AuthorType.Translation)
def load_topics(self): def load_topics(self):
""" """

View File

@ -46,18 +46,9 @@ class Author(BaseModel):
""" """
Author model Author model
""" """
#These types are defined by OpenLyrics: http://openlyrics.info/dataformat.html#authors
TYPE_WORDS = 'words'
TYPE_MUSIC = 'music'
TYPE_TRANSLATION = 'translation'
Types = {
TYPE_WORDS: translate('OpenLP.Ui', 'Words'),
TYPE_MUSIC: translate('OpenLP.Ui', 'Music'),
TYPE_TRANSLATION: translate('OpenLP.Ui', 'Translation')
}
def get_display_name(self, author_type=None): def get_display_name(self, author_type=None):
if author_type: if author_type:
return "%s: %s"%(self.Types[author_type], self.display_name) return "%s: %s"%(AuthorType.Types[author_type], self.display_name)
return self.display_name return self.display_name
class AuthorSong(BaseModel): class AuthorSong(BaseModel):
@ -69,6 +60,19 @@ class AuthorSong(BaseModel):
""" """
pass pass
class AuthorType(object):
"""
Enumeration for Author types.
They are defined by OpenLyrics: http://openlyrics.info/dataformat.html#authors
"""
Words = 'words'
Music = 'music'
Translation = 'translation'
Types = {
Words: translate('OpenLP.Ui', 'Words'),
Music: translate('OpenLP.Ui', 'Music'),
Translation: translate('OpenLP.Ui', 'Translation')
}
class Book(BaseModel): class Book(BaseModel):
""" """

View File

@ -44,7 +44,7 @@ from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm
from openlp.plugins.songs.forms.songimportform import SongImportForm from openlp.plugins.songs.forms.songimportform import SongImportForm
from openlp.plugins.songs.forms.songexportform import SongExportForm from openlp.plugins.songs.forms.songexportform import SongExportForm
from openlp.plugins.songs.lib import VerseType, clean_string, delete_song from openlp.plugins.songs.lib import VerseType, clean_string, delete_song
from openlp.plugins.songs.lib.db import Author, Song, Book, MediaFile from openlp.plugins.songs.lib.db import Author, AuthorType, Song, 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 OpenLyrics, SongXML from openlp.plugins.songs.lib.xml import OpenLyrics, SongXML
@ -467,18 +467,18 @@ class SongMediaItem(MediaManagerItem):
:param item: The service item to be amended :param item: The service item to be amended
:param song: The song to be used to generate the footer :param song: The song to be used to generate the footer
:return List of all authors (only required for initial song generation) :return: List of all authors (only required for initial song generation)
""" """
authors_words = [] authors_words = []
authors_music = [] authors_music = []
authors_translation = [] authors_translation = []
authors_none = [] authors_none = []
for author_song in song.authors_songs: for author_song in song.authors_songs:
if author_song.author_type == Author.TYPE_WORDS: if author_song.author_type == AuthorType.Words:
authors_words.append(author_song.author.display_name) authors_words.append(author_song.author.display_name)
elif author_song.author_type == Author.TYPE_MUSIC: elif author_song.author_type == AuthorType.Music:
authors_music.append(author_song.author.display_name) authors_music.append(author_song.author.display_name)
elif author_song.author_type == Author.TYPE_TRANSLATION: elif author_song.author_type == AuthorType.Translation:
authors_translation.append(author_song.author.display_name) authors_translation.append(author_song.author.display_name)
else: else:
authors_none.append(author_song.author.display_name) authors_none.append(author_song.author.display_name)
@ -491,11 +491,11 @@ class SongMediaItem(MediaManagerItem):
if authors_none: if authors_none:
item.raw_footer.append("%s: %s"%(translate('OpenLP.Ui', 'Written by'), create_separated_list(authors_none))) item.raw_footer.append("%s: %s"%(translate('OpenLP.Ui', 'Written by'), create_separated_list(authors_none)))
if authors_words: if authors_words:
item.raw_footer.append("%s: %s"%(Author.Types[Author.TYPE_WORDS], create_separated_list(authors_words))) item.raw_footer.append("%s: %s"%(AuthorType.Types[AuthorType.Words], create_separated_list(authors_words)))
if authors_music: if authors_music:
item.raw_footer.append("%s: %s"%(Author.Types[Author.TYPE_MUSIC], create_separated_list(authors_music))) item.raw_footer.append("%s: %s"%(AuthorType.Types[AuthorType.Music], create_separated_list(authors_music)))
if authors_translation: if authors_translation:
item.raw_footer.append("%s: %s"%(Author.Types[Author.TYPE_TRANSLATION], create_separated_list(authors_translation))) item.raw_footer.append("%s: %s"%(AuthorType.Types[AuthorType.Translation], create_separated_list(authors_translation)))
if not authors_all: #No authors defined if not authors_all: #No authors defined
item.raw_footer.append(SongStrings.AuthorUnknown) item.raw_footer.append(SongStrings.AuthorUnknown)
item.raw_footer.append(song.copyright) item.raw_footer.append(song.copyright)