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