songbookentry -> songbook_entry, mock_song -> song

This commit is contained in:
Samuel Mehrbrodt 2016-01-09 16:23:11 +01:00
parent fe74a19783
commit ad5246fc4a
5 changed files with 43 additions and 43 deletions

View File

@ -129,10 +129,10 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
author_item.setData(QtCore.Qt.UserRole, (author.id, author_type)) author_item.setData(QtCore.Qt.UserRole, (author.id, author_type))
self.authors_list_view.addItem(author_item) self.authors_list_view.addItem(author_item)
def add_songbookentry_to_list(self, songbook_id, songbook_name, entry): def add_songbook_entry_to_list(self, songbook_id, songbook_name, entry):
songbookentry_item = QtWidgets.QListWidgetItem(SongBookEntry.get_display_name(songbook_name, entry)) songbook_entry_item = QtWidgets.QListWidgetItem(SongBookEntry.get_display_name(songbook_name, entry))
songbookentry_item.setData(QtCore.Qt.UserRole, (songbook_id, entry)) songbook_entry_item.setData(QtCore.Qt.UserRole, (songbook_id, entry))
self.songbooks_list_view.addItem(songbookentry_item) self.songbooks_list_view.addItem(songbook_entry_item)
def _extract_verse_order(self, verse_order): def _extract_verse_order(self, verse_order):
""" """
@ -515,8 +515,8 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
topic_name.setData(QtCore.Qt.UserRole, topic.id) topic_name.setData(QtCore.Qt.UserRole, topic.id)
self.topics_list_view.addItem(topic_name) self.topics_list_view.addItem(topic_name)
self.songbooks_list_view.clear() self.songbooks_list_view.clear()
for songbookentry in self.song.songbookentries: for songbook_entry in self.song.songbook_entries:
self.add_songbookentry_to_list(songbookentry.songbook.id, songbookentry.songbook.name, songbookentry.entry) self.add_songbook_entry_to_list(songbook_entry.songbook.id, songbook_entry.songbook.name, songbook_entry.entry)
self.audio_list_widget.clear() self.audio_list_widget.clear()
for media in self.song.media_files: for media in self.song.media_files:
media_file = QtWidgets.QListWidgetItem(os.path.split(media.file_name)[1]) media_file = QtWidgets.QListWidgetItem(os.path.split(media.file_name)[1])
@ -686,7 +686,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
QtWidgets.QMessageBox.Yes) == QtWidgets.QMessageBox.Yes: QtWidgets.QMessageBox.Yes) == QtWidgets.QMessageBox.Yes:
songbook = Book.populate(name=text) songbook = Book.populate(name=text)
self.manager.save_object(songbook) self.manager.save_object(songbook)
self.add_songbookentry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text())
self.load_songbooks() self.load_songbooks()
self.songbooks_combo_box.setCurrentIndex(0) self.songbooks_combo_box.setCurrentIndex(0)
self.songbook_entry_edit.clear() self.songbook_entry_edit.clear()
@ -699,7 +699,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.EditSongForm', 'This Songbook is already in the list.')) message=translate('SongsPlugin.EditSongForm', 'This Songbook is already in the list.'))
else: else:
self.add_songbookentry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text())
self.songbooks_combo_box.setCurrentIndex(0) self.songbooks_combo_box.setCurrentIndex(0)
self.songbook_entry_edit.clear() self.songbook_entry_edit.clear()
else: else:
@ -1029,13 +1029,13 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
topic = self.manager.get_object(Topic, topic_id) topic = self.manager.get_object(Topic, topic_id)
if topic is not None: if topic is not None:
self.song.topics.append(topic) self.song.topics.append(topic)
self.song.songbookentries = [] self.song.songbook_entries = []
for row in range(self.songbooks_list_view.count()): for row in range(self.songbooks_list_view.count()):
item = self.songbooks_list_view.item(row) item = self.songbooks_list_view.item(row)
songbook_id = item.data(QtCore.Qt.UserRole)[0] songbook_id = item.data(QtCore.Qt.UserRole)[0]
songbook = self.manager.get_object(Book, songbook_id) songbook = self.manager.get_object(Book, songbook_id)
entry = item.data(QtCore.Qt.UserRole)[1] entry = item.data(QtCore.Qt.UserRole)[1]
self.song.add_songbookentry(songbook, entry) self.song.add_songbook_entry(songbook, entry)
# Save the song here because we need a valid id for the audio files. # Save the song here because we need a valid id for the audio files.
clean_song(self.manager, self.song) clean_song(self.manager, self.song)
self.manager.save_object(self.song) self.manager.save_object(self.song)

View File

@ -160,21 +160,21 @@ class Song(BaseModel):
self.authors_songs.remove(author_song) self.authors_songs.remove(author_song)
return return
def add_songbookentry(self, songbook, entry): def add_songbook_entry(self, songbook, entry):
""" """
Add a Songbook Entry to the song if it not yet exists Add a Songbook Entry to the song if it not yet exists
:param songbook_name: Name of the Songbook. :param songbook_name: Name of the Songbook.
:param entry: Entry in the Songbook (usually a number) :param entry: Entry in the Songbook (usually a number)
""" """
for songbookentry in self.songbookentries: for songbook_entry in self.songbook_entries:
if songbookentry.songbook.name == songbook.name and songbookentry.entry == entry: if songbook_entry.songbook.name == songbook.name and songbook_entry.entry == entry:
return return
new_songbookentry = SongBookEntry() new_songbook_entry = SongBookEntry()
new_songbookentry.songbook = songbook new_songbook_entry.songbook = songbook
new_songbookentry.entry = entry new_songbook_entry.entry = entry
self.songbookentries.append(new_songbookentry) self.songbook_entries.append(new_songbook_entry)
class SongBookEntry(BaseModel): class SongBookEntry(BaseModel):
@ -383,7 +383,7 @@ def init_schema(url):
# Use lazy='joined' to always load authors when the song is fetched from the database (bug 1366198) # Use lazy='joined' to always load authors when the song is fetched from the database (bug 1366198)
'authors': relation(Author, secondary=authors_songs_table, viewonly=True, lazy='joined'), 'authors': relation(Author, secondary=authors_songs_table, viewonly=True, lazy='joined'),
'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),
'songbookentries': relation(SongBookEntry, backref='song', cascade="all, delete-orphan"), 'songbook_entries': relation(SongBookEntry, backref='song', cascade="all, delete-orphan"),
'topics': relation(Topic, backref='songs', secondary=songs_topics_table) 'topics': relation(Topic, backref='songs', secondary=songs_topics_table)
}) })
mapper(Topic, topics_table) mapper(Topic, topics_table)

View File

@ -254,20 +254,20 @@ class SongMediaItem(MediaManagerItem):
search_book = search_keywords[0] search_book = search_keywords[0]
search_entry = re.sub(r'[^0-9]', '', search_keywords[2]) search_entry = re.sub(r'[^0-9]', '', search_keywords[2])
songbookentries = (self.plugin.manager.session.query(SongBookEntry) songbook_entries = (self.plugin.manager.session.query(SongBookEntry)
.join(Book) .join(Book)
.order_by(Book.name) .order_by(Book.name)
.order_by(SongBookEntry.entry)) .order_by(SongBookEntry.entry))
for songbookentry in songbookentries: for songbook_entry in songbook_entries:
if songbookentry.song.temporary: if songbook_entry.song.temporary:
continue continue
if search_book.lower() not in songbookentry.songbook.name.lower(): if search_book.lower() not in songbook_entry.songbook.name.lower():
continue continue
if search_entry not in songbookentry.entry: if search_entry not in songbook_entry.entry:
continue continue
song_detail = '%s #%s: %s' % (songbookentry.songbook.name, songbookentry.entry, songbookentry.song.title) song_detail = '%s #%s: %s' % (songbook_entry.songbook.name, songbook_entry.entry, songbook_entry.song.title)
song_name = QtWidgets.QListWidgetItem(song_detail) song_name = QtWidgets.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, songbookentry.song.id) song_name.setData(QtCore.Qt.UserRole, songbook_entry.song.id)
self.list_view.addItem(song_name) self.list_view.addItem(song_name)
def on_clear_text_button_click(self): def on_clear_text_button_click(self):
@ -523,8 +523,8 @@ class SongMediaItem(MediaManagerItem):
item.raw_footer.append("%s %s" % (SongStrings.CopyrightSymbol, song.copyright)) item.raw_footer.append("%s %s" % (SongStrings.CopyrightSymbol, song.copyright))
else: else:
item.raw_footer.append(song.copyright) item.raw_footer.append(song.copyright)
if self.display_songbook and song.songbookentries: if self.display_songbook and song.songbook_entries:
songbooks = [str(songbookentry) for songbookentry in song.songbookentries] songbooks = [str(songbook_entry) for songbook_entry in song.songbook_entries]
item.raw_footer.append(", ".join(songbooks)) item.raw_footer.append(", ".join(songbooks))
if Settings().value('core/ccli number'): if Settings().value('core/ccli number'):
item.raw_footer.append(translate('SongsPlugin.MediaItem', item.raw_footer.append(translate('SongsPlugin.MediaItem',

View File

@ -266,12 +266,12 @@ class OpenLyrics(object):
element.set('type', AuthorType.Music) element.set('type', AuthorType.Music)
else: else:
element.set('type', author_song.author_type) element.set('type', author_song.author_type)
if song.songbookentries: if song.songbook_entries:
songbooks = etree.SubElement(properties, 'songbooks') songbooks = etree.SubElement(properties, 'songbooks')
for songbookentry in song.songbookentries: for songbook_entry in song.songbook_entries:
element = self._add_text_to_element('songbook', songbooks, None, songbookentry.songbook.name) element = self._add_text_to_element('songbook', songbooks, None, songbook_entry.songbook.name)
if songbookentry.entry: if songbook_entry.entry:
element.set('entry', songbookentry.entry) element.set('entry', songbook_entry.entry)
if song.topics: if song.topics:
themes = etree.SubElement(properties, 'themes') themes = etree.SubElement(properties, 'themes')
for topic in song.topics: for topic in song.topics:
@ -752,7 +752,7 @@ class OpenLyrics(object):
# We need to create a book, because it does not exist. # We need to create a book, because it does not exist.
book = Book.populate(name=book_name, publisher='') book = Book.populate(name=book_name, publisher='')
self.manager.save_object(book) self.manager.save_object(book)
song.add_songbookentry(book, songbook.get('entry', '')) song.add_songbook_entry(book, songbook.get('entry', ''))
def _process_titles(self, properties, song): def _process_titles(self, properties, song):
""" """

View File

@ -155,29 +155,29 @@ class TestMediaItem(TestCase, TestMixin):
Test build songs footer with basic song and multiple songbooks Test build songs footer with basic song and multiple songbooks
""" """
# GIVEN: A Song and a Service Item # GIVEN: A Song and a Service Item
mock_song = Song() song = Song()
mock_song.title = 'My Song' song.title = 'My Song'
mock_song.copyright = 'My copyright' song.copyright = 'My copyright'
mock_song.authors_songs = [] song.authors_songs = []
mock_song.ccli_number = '' song.ccli_number = ''
book1 = MagicMock() book1 = MagicMock()
book1.name = "My songbook" book1.name = "My songbook"
book2 = MagicMock() book2 = MagicMock()
book2.name = "Thy songbook" book2.name = "Thy songbook"
mock_song.songbookentries = [] song.songbookentries = []
mock_song.add_songbookentry(book1, '12') song.add_songbookentry(book1, '12')
mock_song.add_songbookentry(book2, '502A') song.add_songbookentry(book2, '502A')
service_item = ServiceItem(None) service_item = ServiceItem(None)
# WHEN: I generate the Footer with default settings # WHEN: I generate the Footer with default settings
self.media_item.generate_footer(service_item, mock_song) self.media_item.generate_footer(service_item, song)
# THEN: The songbook should not be in the footer # THEN: The songbook should not be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright']) self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
# WHEN: I activate the "display songbook" option # WHEN: I activate the "display songbook" option
self.media_item.display_songbook = True self.media_item.display_songbook = True
self.media_item.generate_footer(service_item, mock_song) self.media_item.generate_footer(service_item, song)
# THEN: The songbook should be in the footer # THEN: The songbook should be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A']) self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A'])