~tomasgroth/openlp/pylint-fixes

« back to all changes in this revision

Viewing changes to openlp/plugins/songs/lib/mediaitem.py

  • Committer: Raoul Snyman
  • Author(s): Samuel Mehrbrodt
  • Date: 2019-04-09 06:07:24 UTC
  • mfrom: (2745.3.19 bug-1695620)
  • Revision ID: raoul@snyman.info-20190409060724-08lntpbjx9pwe64r
Make footer configurable

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
###############################################################################
22
22
import logging
23
23
import os
 
24
import mako
24
25
 
25
26
from PyQt5 import QtCore, QtWidgets
26
27
from sqlalchemy.sql import and_, or_
35
36
from openlp.core.lib.mediamanageritem import MediaManagerItem
36
37
from openlp.core.lib.plugin import PluginStatus
37
38
from openlp.core.lib.serviceitem import ItemCapabilities
38
 
from openlp.core.lib.ui import create_widget_action
 
39
from openlp.core.lib.ui import create_widget_action, critical_error_message_box
39
40
from openlp.core.ui.icons import UiIcons
40
41
from openlp.plugins.songs.forms.editsongform import EditSongForm
41
42
from openlp.plugins.songs.forms.songexportform import SongExportForm
131
132
        self.is_search_as_you_type_enabled = Settings().value('advanced/search as type')
132
133
        self.update_service_on_edit = Settings().value(self.settings_section + '/update service on edit')
133
134
        self.add_song_from_service = Settings().value(self.settings_section + '/add song from service')
134
 
        self.display_songbook = Settings().value(self.settings_section + '/display songbook')
135
 
        self.display_written_by_text = Settings().value(self.settings_section + '/display written by')
136
 
        self.display_copyright_symbol = Settings().value(self.settings_section + '/display copyright symbol')
137
135
 
138
136
    def retranslate_ui(self):
139
137
        self.search_text_label.setText('{text}:'.format(text=UiStrings().Search))
677
675
        item.raw_footer = []
678
676
        item.raw_footer.append(song.title)
679
677
        if authors_none:
680
 
            # If the setting for showing "Written by:" is enabled, show it before unspecified authors.
681
 
            if Settings().value('songs/display written by'):
682
 
                item.raw_footer.append("{text}: {authors}".format(text=translate('OpenLP.Ui', 'Written by'),
683
 
                                                                  authors=create_separated_list(authors_none)))
684
 
            else:
685
 
                item.raw_footer.append("{authors}".format(authors=create_separated_list(authors_none)))
 
678
            item.raw_footer.append("{text}: {authors}".format(text=translate('OpenLP.Ui', 'Written by'),
 
679
                                                              authors=create_separated_list(authors_none)))
686
680
        if authors_words_music:
687
681
            item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.WordsAndMusic],
688
682
                                                              authors=create_separated_list(authors_words_music)))
696
690
            item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Translation],
697
691
                                                              authors=create_separated_list(authors_translation)))
698
692
        if song.copyright:
699
 
            if self.display_copyright_symbol:
700
 
                item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol,
701
 
                                                                song=song.copyright))
702
 
            else:
703
 
                item.raw_footer.append(song.copyright)
704
 
        if self.display_songbook and song.songbook_entries:
705
 
            songbooks = [str(songbook_entry) for songbook_entry in song.songbook_entries]
 
693
            item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol,
 
694
                                                            song=song.copyright))
 
695
        songbooks = [str(songbook_entry) for songbook_entry in song.songbook_entries]
 
696
        if song.songbook_entries:
706
697
            item.raw_footer.append(", ".join(songbooks))
707
698
        if Settings().value('core/ccli number'):
708
 
            item.raw_footer.append(translate('SongsPlugin.MediaItem',
709
 
                                             'CCLI License: ') + Settings().value('core/ccli number'))
710
 
        item.metadata.append('<em>{label}:</em> {title}'.format(label=translate('SongsPlugin.MediaItem', 'Title'),
711
 
                                                                title=song.title))
712
 
        if song.alternate_title:
713
 
            item.metadata.append('<em>{label}:</em> {title}'.
714
 
                                 format(label=translate('SongsPlugin.MediaItem', 'Alt Title'),
715
 
                                        title=song.alternate_title))
716
 
        if song.songbook_entries:
717
 
            for songbook_entry in song.songbook_entries:
718
 
                item.metadata.append('<em>{label}:</em> {book}/{num}/{pub}'.
719
 
                                     format(label=translate('SongsPlugin.MediaItem', 'Songbook'),
720
 
                                            book=songbook_entry.songbook.name,
721
 
                                            num=songbook_entry.entry,
722
 
                                            pub=songbook_entry.songbook.publisher))
723
 
        if song.topics:
724
 
            for topics in song.topics:
725
 
                item.metadata.append('<em>{label}:</em> {topic}'.
726
 
                                     format(label=translate('SongsPlugin.MediaItem', 'Topic'), topic=topics.name))
 
699
            item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') +
 
700
                                   Settings().value('core/ccli number'))
 
701
        footer_template = Settings().value('songs/footer template')
 
702
        # Keep this in sync with the list in songstab.py
 
703
        vars = {
 
704
            'title': song.title,
 
705
            'alternate_title': song.alternate_title,
 
706
            'authors_none_label': translate('OpenLP.Ui', 'Written by'),
 
707
            'authors_none': authors_none,
 
708
            'authors_words_label': AuthorType.Types[AuthorType.Words],
 
709
            'authors_words': authors_words,
 
710
            'authors_music_label': AuthorType.Types[AuthorType.Music],
 
711
            'authors_music': authors_music,
 
712
            'authors_words_music_label': AuthorType.Types[AuthorType.WordsAndMusic],
 
713
            'authors_words_music': authors_words_music,
 
714
            'authors_translation_label': AuthorType.Types[AuthorType.Translation],
 
715
            'authors_translation': authors_translation,
 
716
            'authors_words_all': authors_words + authors_words_music,
 
717
            'authors_music_all': authors_music + authors_words_music,
 
718
            'copyright': song.copyright,
 
719
            'songbook_entries': songbooks,
 
720
            'ccli_license': Settings().value('core/ccli number'),
 
721
            'ccli_license_label': translate('SongsPlugin.MediaItem', 'CCLI License'),
 
722
            'ccli_number': song.ccli_number,
 
723
            'topics': [topic.name for topic in song.topics]
 
724
        }
 
725
        try:
 
726
            item.footer_html = mako.template.Template(footer_template).render_unicode(**vars).replace('\n', '')
 
727
        except mako.exceptions.SyntaxException:
 
728
            log.error('Failed to render Song footer html:\n' + mako.exceptions.text_error_template().render())
 
729
            critical_error_message_box(message=translate('SongsPlugin.MediaItem',
 
730
                                                         'Failed to render Song footer html.\nSee log for details'))
727
731
        return authors_all
728
732
 
729
733
    def service_load(self, item):