← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~orangeshirt/openlp/search_for_songbooks into lp:openlp

 

Armin Köhler has proposed merging lp:~orangeshirt/openlp/search_for_songbooks into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #789666 in OpenLP: "Allow song search by song book/number"
  https://bugs.launchpad.net/openlp/+bug/789666

For more details, see:
https://code.launchpad.net/~orangeshirt/openlp/search_for_songbooks/+merge/94693

Add possibility to serch for songbook and/or songnumber in the songlist.
Fix Bug #789666
-- 
https://code.launchpad.net/~orangeshirt/openlp/search_for_songbooks/+merge/94693
Your team OpenLP Core is requested to review the proposed merge of lp:~orangeshirt/openlp/search_for_songbooks into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2012-02-16 20:36:35 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2012-02-26 21:38:25 +0000
@@ -43,7 +43,7 @@
     SongImportForm, SongExportForm
 from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
     clean_string
-from openlp.plugins.songs.lib.db import Author, Song, MediaFile
+from openlp.plugins.songs.lib.db import Author, Song, Book, MediaFile
 from openlp.plugins.songs.lib.ui import SongStrings
 
 log = logging.getLogger(__name__)
@@ -56,7 +56,8 @@
     Titles = 2
     Lyrics = 3
     Authors = 4
-    Themes = 5
+    Books = 5
+    Themes = 6
 
 
 class SongMediaItem(MediaManagerItem):
@@ -158,6 +159,8 @@
                 translate('SongsPlugin.MediaItem', 'Lyrics')),
             (SongSearch.Authors, u':/songs/song_search_author.png',
                 SongStrings.Authors),
+            (SongSearch.Books, u':/songs/song_book_edit.png',
+                 SongStrings.SongBooks),
             (SongSearch.Themes, u':/slides/slide_theme.png', UiStrings().Themes)
         ])
         self.searchTextEdit.setCurrentSearchType(QtCore.QSettings().value(
@@ -196,6 +199,19 @@
                 Author.display_name.like(u'%' + search_keywords + u'%'),
                 Author.display_name.asc())
             self.displayResultsAuthor(search_results)
+        elif search_type == SongSearch.Books:
+            log.debug(u'Books Search')
+            search_results = self.plugin.manager.get_all_objects(Book,
+                Book.name.like(u'%' + search_keywords + u'%'),
+                Book.name.asc())
+            song_number = False
+            if not search_results:
+                search_keywords = search_keywords.rpartition(' ')
+                search_results = self.plugin.manager.get_all_objects(Book,
+                    Book.name.like(u'%' + search_keywords[0] + u'%'),
+                    Book.name.asc())
+                song_number = re.sub(r'[^0-9]', u'', search_keywords[2])
+            self.displayResultsBook(search_results, song_number)
         elif search_type == SongSearch.Themes:
             log.debug(u'Theme Search')
             search_results = self.plugin.manager.get_all_objects(Song,
@@ -270,6 +286,25 @@
                 song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
                 self.listView.addItem(song_name)
 
+    def displayResultsBook(self, searchresults, song_number=False):
+        log.debug(u'display results Book')
+        self.listView.clear()
+        for book in searchresults:
+            songs = sorted(book.songs, key=lambda song: int(
+                re.sub(r'[^0-9]', u' ', song.song_number).partition(' ')[0])
+                if len(re.sub(r'[^\w]', ' ', song.song_number)) else 0)
+            for song in songs:
+                # Do not display temporary songs
+                if song.temporary:
+                    continue
+                if song_number and not song_number in song.song_number:
+                    continue
+                song_detail = u'%s - %s (%s)' % (book.name, song.song_number,
+                    song.title)
+                song_name = QtGui.QListWidgetItem(song_detail)
+                song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
+                self.listView.addItem(song_name)
+
     def onClearTextButtonClick(self):
         """
         Clear the search text.


Follow ups