forked from openlp/openlp
Magic number -> SongSearch
This commit is contained in:
parent
bffa44a1cb
commit
ad03f8588e
@ -33,16 +33,26 @@ from sqlalchemy.sql import or_
|
||||
|
||||
from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
|
||||
translate, check_item_selected, PluginStatus, StringContent
|
||||
from openlp.core.lib.searchedit import SearchEdit
|
||||
from openlp.core.lib.ui import UiStrings
|
||||
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
||||
SongImportForm, SongExportForm
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML
|
||||
from openlp.plugins.songs.lib.db import Author, Song
|
||||
from openlp.plugins.songs.lib.ui import SongStrings
|
||||
from openlp.core.lib.searchedit import SearchEdit
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class SongSearch(object):
|
||||
"""
|
||||
An enumeration for song search methods.
|
||||
"""
|
||||
Entire = 1
|
||||
Titles = 2
|
||||
Lyrics = 3
|
||||
Authors = 4
|
||||
Themes = 5
|
||||
|
||||
class SongMediaItem(MediaManagerItem):
|
||||
"""
|
||||
This is the custom media manager item for Songs.
|
||||
@ -134,14 +144,15 @@ class SongMediaItem(MediaManagerItem):
|
||||
|
||||
def initialise(self):
|
||||
self.searchTextEdit.setSearchTypes([
|
||||
(1, u':/songs/song_search_all.png',
|
||||
(SongSearch.Entire, u':/songs/song_search_all.png',
|
||||
translate('SongsPlugin.MediaItem', 'Entire Song')),
|
||||
(2, u':/songs/song_search_title.png',
|
||||
(SongSearch.Titles, u':/songs/song_search_title.png',
|
||||
translate('SongsPlugin.MediaItem', 'Titles')),
|
||||
(3, u':/songs/song_search_lyrics.png',
|
||||
(SongSearch.Lyrics, u':/songs/song_search_lyrics.png',
|
||||
translate('SongsPlugin.MediaItem', 'Lyrics')),
|
||||
(4, u':/songs/song_search_author.png', SongStrings.Authors),
|
||||
(5, u':/slides/slide_theme.png', UiStrings.Themes)
|
||||
(SongSearch.Authors, u':/songs/song_search_author.png',
|
||||
SongStrings.Authors),
|
||||
(SongSearch.Themes, u':/slides/slide_theme.png', UiStrings.Themes)
|
||||
])
|
||||
self.configUpdated()
|
||||
|
||||
@ -150,7 +161,7 @@ class SongMediaItem(MediaManagerItem):
|
||||
search_results = []
|
||||
# search_type = self.searchTypeComboBox.currentIndex()
|
||||
search_type = self.searchTextEdit.currentSearchType()
|
||||
if search_type == 1:
|
||||
if search_type == SongSearch.Entire:
|
||||
log.debug(u'Entire Song Search')
|
||||
search_results = self.parent.manager.get_all_objects(Song,
|
||||
or_(Song.search_title.like(u'%' + self.whitespace.sub(u' ',
|
||||
@ -158,25 +169,25 @@ class SongMediaItem(MediaManagerItem):
|
||||
Song.search_lyrics.like(u'%' + search_keywords.lower() + \
|
||||
u'%')), Song.search_title.asc())
|
||||
self.displayResultsSong(search_results)
|
||||
if search_type == 2:
|
||||
elif search_type == SongSearch.Titles:
|
||||
log.debug(u'Titles Search')
|
||||
search_results = self.parent.manager.get_all_objects(Song,
|
||||
Song.search_title.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords.lower()) + u'%'), Song.search_title.asc())
|
||||
self.displayResultsSong(search_results)
|
||||
elif search_type == 3:
|
||||
elif search_type == SongSearch.Lyrics:
|
||||
log.debug(u'Lyrics Search')
|
||||
search_results = self.parent.manager.get_all_objects(Song,
|
||||
Song.search_lyrics.like(u'%' + search_keywords.lower() + u'%'),
|
||||
Song.search_lyrics.asc())
|
||||
self.displayResultsSong(search_results)
|
||||
elif search_type == 4:
|
||||
elif search_type == SongSearch.Authors:
|
||||
log.debug(u'Authors Search')
|
||||
search_results = self.parent.manager.get_all_objects(Author,
|
||||
Author.display_name.like(u'%' + search_keywords + u'%'),
|
||||
Author.display_name.asc())
|
||||
self.displayResultsAuthor(search_results)
|
||||
elif search_type == 5:
|
||||
elif search_type == SongSearch.Themes:
|
||||
log.debug(u'Theme Search')
|
||||
search_results = self.parent.manager.get_all_objects(Song,
|
||||
Song.theme_name == search_keywords, Song.search_lyrics.asc())
|
||||
|
Loading…
Reference in New Issue
Block a user