adapt the second_bible searchfunction to the new book name scheme

This commit is contained in:
Armin Köhler 2011-03-17 21:54:22 +01:00
parent 7a15251ffc
commit a23d902fa5
3 changed files with 52 additions and 5 deletions

View File

@ -357,6 +357,17 @@ class BibleDB(QtCore.QObject, Manager):
""" """
return self.get_all_objects(Book, order_by_ref=Book.id) return self.get_all_objects(Book, order_by_ref=Book.id)
def get_book_by_book_ref_id(self, id):
"""
Return a book object from the database.
``book``
The name of the book to return.
"""
log.debug(u'BibleDb.get_book_by_book_ref_id("%s")', id)
db_book = self.get_object_filtered(Book, Book.book_reference_id.like(id))
return db_book
def get_verses(self, reference_list, en_reference_list): def get_verses(self, reference_list, en_reference_list):
""" """
This is probably the most used function. It retrieves the list of This is probably the most used function. It retrieves the list of
@ -864,6 +875,26 @@ class SpellingDB(QtCore.QObject, Manager):
else: else:
return id[0] return id[0]
def get_book_name_by_reference_id(self, id, language):
"""
Return the name of a book by id and language.
``id``
The name to search the id.
``language``
The language for which should be searched
"""
log.debug(u'SpellingDB.get_book_name_by_reference_id("%s", "%s")', id,
language)
name = self.session.query(Spelling.name)\
.filter(Spelling.book_reference_id.like(id))\
.filter(Spelling.language_id.like(language)).first()
if not name:
return None
else:
return unicode(name[0])
def create_spelling(self, name, book_reference_id, language_id): def create_spelling(self, name, book_reference_id, language_id):
""" """
Add a spelling to the database. Add a spelling to the database.

View File

@ -255,7 +255,7 @@ class BibleManager(object):
book = self.get_book_ref(book, int(language_id.value)) book = self.get_book_ref(book, int(language_id.value))
return self.db_cache[bible].get_verse_count(book, chapter) return self.db_cache[bible].get_verse_count(book, chapter)
def get_verses(self, bible, versetext): def get_verses(self, bible, versetext, secondbible=False):
""" """
Parses a scripture reference, fetches the verses from the Bible Parses a scripture reference, fetches the verses from the Bible
specified, and returns a list of ``Verse`` objects. specified, and returns a list of ``Verse`` objects.
@ -286,13 +286,29 @@ class BibleManager(object):
return None return None
reflist = parse_reference(versetext) reflist = parse_reference(versetext)
if reflist: if reflist:
log.debug(u'reflist:%s', reflist) # if we use a second bible we have to rename the book names
if secondbible:
log.debug(u'BibleManager.get_verses("secondbible true")')
meta = self.db_cache[bible].get_object(BibleMeta,
u'language_id')
language_id = meta.value
new_reflist = []
for item in reflist:
if item:
book = self.get_book_ref(item[0])
book_ref_id = self.parent.manager.\
get_book_ref_id_by_name(book, language_id)
book = self.db_cache[bible].get_book_by_book_ref_id(
book_ref_id)
new_reflist.append((book.name, item[1], item[2], item[3]))
reflist = new_reflist
log.debug(u'BibleManager.get_verses("reflist: %s")', reflist)
en_reflist = [] en_reflist = []
for item in reflist: for item in reflist:
if item: if item:
book = self.get_book_ref(item[0]) book = self.get_book_ref(item[0])
en_reflist.append((book, item[1], item[2], item[3])) en_reflist.append((book, item[1], item[2], item[3]))
log.debug(u'en_reflist:%s', en_reflist) log.debug(u'BibleManager.get_verses("en_reflist: %s")', en_reflist)
return self.db_cache[bible].get_verses(reflist, en_reflist) return self.db_cache[bible].get_verses(reflist, en_reflist)
else: else:
Receiver.send_message(u'openlp_information_message', { Receiver.send_message(u'openlp_information_message', {

View File

@ -482,7 +482,7 @@ class BibleMediaItem(MediaManagerItem):
self.search_results = self.parent.manager.get_verses(bible, versetext) self.search_results = self.parent.manager.get_verses(bible, versetext)
if second_bible: if second_bible:
self.second_search_results = self.parent.manager.get_verses( self.second_search_results = self.parent.manager.get_verses(
second_bible, versetext) second_bible, versetext, True)
if self.advancedClearComboBox.currentIndex() == 0: if self.advancedClearComboBox.currentIndex() == 0:
self.listView.clear() self.listView.clear()
if self.listView.count() != 0: if self.listView.count() != 0:
@ -509,7 +509,7 @@ class BibleMediaItem(MediaManagerItem):
self.search_results = self.parent.manager.get_verses(bible, text) self.search_results = self.parent.manager.get_verses(bible, text)
if second_bible and self.search_results: if second_bible and self.search_results:
self.second_search_results = self.parent.manager.get_verses( self.second_search_results = self.parent.manager.get_verses(
second_bible, text) second_bible, text, True)
else: else:
# We are doing a 'Text Search'. # We are doing a 'Text Search'.
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')