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. Run the wizard.
""" """
self.setDefaults() self.set_defaults()
return QtGui.QWizard.exec_(self) return QtGui.QWizard.exec_(self)
def reject(self): def reject(self):

View File

@ -275,8 +275,9 @@ def init_schema(url):
mapper(Book, song_books_table) mapper(Book, song_books_table)
mapper(MediaFile, media_files_table) mapper(MediaFile, media_files_table)
mapper(Song, songs_table, properties={ 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_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'), 'book': relation(Book, backref='songs'),
'media_files': relation(MediaFile, backref='songs', order_by=media_files_table.c.weight), 'media_files': relation(MediaFile, backref='songs', order_by=media_files_table.c.weight),
'topics': relation(Topic, backref='songs', secondary=songs_topics_table) '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.common import translate
from openlp.core.lib import FormattingTags from openlp.core.lib import FormattingTags
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 Author, Book, Song, Topic from openlp.plugins.songs.lib.db import Author, AuthorSong, Book, Song, Topic
from openlp.core.utils import get_application_version from openlp.core.utils import get_application_version
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -166,7 +166,7 @@ class OpenLyrics(object):
supported by the :class:`OpenLyrics` class: supported by the :class:`OpenLyrics` class:
``<authors>`` ``<authors>``
OpenLP does not support the attribute *type* and *lang*. OpenLP does not support the attribute *lang*.
``<chord>`` ``<chord>``
This property is not supported. This property is not supported.
@ -269,10 +269,12 @@ class OpenLyrics(object):
'verseOrder', properties, song.verse_order.lower()) 'verseOrder', properties, song.verse_order.lower())
if song.ccli_number: if song.ccli_number:
self._add_text_to_element('ccliNo', properties, 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') authors = etree.SubElement(properties, 'authors')
for author in song.authors: for author_song in song.authors_songs:
self._add_text_to_element('author', authors, author.display_name) 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) book = self.manager.get_object_filtered(Book, Book.id == song.song_book_id)
if book is not None: if book is not None:
book = book.name book = book.name
@ -501,16 +503,20 @@ class OpenLyrics(object):
if hasattr(properties, 'authors'): if hasattr(properties, 'authors'):
for author in properties.authors.author: for author in properties.authors.author:
display_name = self._text(author) display_name = self._text(author)
author_type = author.get('type', '')
if display_name: if display_name:
authors.append(display_name) authors.append((display_name, author_type))
for display_name in authors: for (display_name, author_type) in authors:
author = self.manager.get_object_filtered(Author, Author.display_name == display_name) author = self.manager.get_object_filtered(Author, Author.display_name == display_name)
if author is None: if author is None:
# We need to create a new author, as the author does not exist. # We need to create a new author, as the author does not exist.
author = Author.populate(display_name=display_name, author = Author.populate(display_name=display_name,
last_name=display_name.split(' ')[-1], last_name=display_name.split(' ')[-1],
first_name=' '.join(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): def _process_cclinumber(self, properties, song):
""" """