← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~minkus/openlp/searchfields into lp:openlp

 

Chris Hill has proposed merging lp:~minkus/openlp/searchfields into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1000729 in OpenLP: "Support more song fields in the search"
  https://bugs.launchpad.net/openlp/+bug/1000729

For more details, see:
https://code.launchpad.net/~minkus/openlp/searchfields/+merge/246954

Partial fix for #1000729. Adds 'Topic' searching, based on the existing 'Author' search. Might want to create a new icon - 16x16 version of resources/images/topic_maintenance.png? This was the only part I couldn't get to work... Hope it's OK, this is my first time :)
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~minkus/openlp/searchfields into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2015-01-18 13:39:21 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2015-01-19 21:52:41 +0000
@@ -37,7 +37,7 @@
 from openlp.plugins.songs.forms.songimportform import SongImportForm
 from openlp.plugins.songs.forms.songexportform import SongExportForm
 from openlp.plugins.songs.lib import VerseType, clean_string, delete_song
-from openlp.plugins.songs.lib.db import Author, AuthorType, Song, Book, MediaFile
+from openlp.plugins.songs.lib.db import Author, AuthorType, Song, Book, MediaFile, Topic
 from openlp.plugins.songs.lib.ui import SongStrings
 from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics, SongXML
 
@@ -53,7 +53,8 @@
     Lyrics = 3
     Authors = 4
     Books = 5
-    Themes = 6
+    Topics = 6
+    Themes = 7
 
 
 class SongMediaItem(MediaManagerItem):
@@ -149,6 +150,8 @@
                 translate('SongsPlugin.MediaItem', 'Search Authors...')),
             (SongSearch.Books, ':/songs/song_book_edit.png', SongStrings.SongBooks,
                 translate('SongsPlugin.MediaItem', 'Search Song Books...')),
+            (SongSearch.Topics, ':/songs/topic_add.png', SongStrings.Topics,
+                translate('SongsPlugin.MediaItem', 'Search Topics...')),
             (SongSearch.Themes, ':/slides/slide_theme.png', UiStrings().Themes, UiStrings().SearchThemes)
         ])
         self.search_text_edit.set_current_search_type(Settings().value('%s/last search type' % self.settings_section))
@@ -192,6 +195,12 @@
                                                                      Book.name.like(search_string), Book.name.asc())
                 song_number = re.sub(r'[^0-9]', '', search_keywords[2])
             self.display_results_book(search_results, song_number)
+        elif search_type == SongSearch.Topics:
+            log.debug('Topics Search')
+            search_string = '%' + search_keywords + '%'
+            search_results = self.plugin.manager.get_all_objects(
+                Topic, Topic.name.like(search_string), Topic.name.asc())
+            self.display_results_topic(search_results)
         elif search_type == SongSearch.Themes:
             log.debug('Theme Search')
             search_string = '%' + search_keywords + '%'
@@ -267,6 +276,19 @@
                 song_name.setData(QtCore.Qt.UserRole, song.id)
                 self.list_view.addItem(song_name)
 
+    def display_results_topic(self, search_results):
+        log.debug('display results Topic')
+        self.list_view.clear()
+        for topic in search_results:
+            for song in topic.songs:
+                # Do not display temporary songs
+                if song.temporary:
+                    continue
+                song_detail = '%s (%s)' % (topic.name, song.title)
+                song_name = QtGui.QListWidgetItem(song_detail)
+                song_name.setData(QtCore.Qt.UserRole, song.id)
+                self.list_view.addItem(song_name)
+
     def on_clear_text_button_click(self):
         """
         Clear the search text.


Follow ups