Add support for author types to OpenLyrics import and export

This commit is contained in:
Samuel Mehrbrodt 2014-03-30 23:42:46 +02:00
parent c98970d0e4
commit ad9717ea42
3 changed files with 17 additions and 10 deletions

View File

@ -197,7 +197,7 @@ class OpenLPWizard(QtGui.QWizard, RegistryProperties):
"""
Run the wizard.
"""
self.setDefaults()
self.set_defaults()
return QtGui.QWizard.exec_(self)
def reject(self):

View File

@ -275,8 +275,9 @@ def init_schema(url):
mapper(Book, song_books_table)
mapper(MediaFile, media_files_table)
mapper(Song, songs_table, properties={
# Use the authors_songs relation when you need access to the 'author_type' attribute.
'authors_songs': relation(AuthorSong, cascade="all, delete-orphan"),
'authors': relation(Author, secondary=authors_songs_table, viewonly=True),
'authors': relation(Author, secondary=authors_songs_table),
'book': relation(Book, backref='songs'),
'media_files': relation(MediaFile, backref='songs', order_by=media_files_table.c.weight),
'topics': relation(Topic, backref='songs', secondary=songs_topics_table)

View File

@ -71,7 +71,7 @@ from lxml import etree, objectify
from openlp.core.common import translate
from openlp.core.lib import FormattingTags
from openlp.plugins.songs.lib import VerseType, clean_song
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic
from openlp.plugins.songs.lib.db import Author, AuthorSong, Book, Song, Topic
from openlp.core.utils import get_application_version
log = logging.getLogger(__name__)
@ -166,7 +166,7 @@ class OpenLyrics(object):
supported by the :class:`OpenLyrics` class:
``<authors>``
OpenLP does not support the attribute *type* and *lang*.
OpenLP does not support the attribute *lang*.
``<chord>``
This property is not supported.
@ -269,10 +269,12 @@ class OpenLyrics(object):
'verseOrder', properties, song.verse_order.lower())
if song.ccli_number:
self._add_text_to_element('ccliNo', properties, song.ccli_number)
if song.authors:
if song.authors_songs:
authors = etree.SubElement(properties, 'authors')
for author in song.authors:
self._add_text_to_element('author', authors, author.display_name)
for author_song in song.authors_songs:
element = self._add_text_to_element('author', authors, author_song.author.display_name)
if author_song.author_type:
element.set('type', author_song.author_type)
book = self.manager.get_object_filtered(Book, Book.id == song.song_book_id)
if book is not None:
book = book.name
@ -501,16 +503,20 @@ class OpenLyrics(object):
if hasattr(properties, 'authors'):
for author in properties.authors.author:
display_name = self._text(author)
author_type = author.get('type', '')
if display_name:
authors.append(display_name)
for display_name in authors:
authors.append((display_name, author_type))
for (display_name, author_type) in authors:
author = self.manager.get_object_filtered(Author, Author.display_name == display_name)
if author is None:
# We need to create a new author, as the author does not exist.
author = Author.populate(display_name=display_name,
last_name=display_name.split(' ')[-1],
first_name=' '.join(display_name.split(' ')[:-1]))
song.authors.append(author)
author_song = AuthorSong()
author_song.author = author
author_song.author_type = author_type
song.authors_songs.append(author_song)
def _process_cclinumber(self, properties, song):
"""