forked from openlp/openlp
moved get_book_ref_id_by_name() from BibleManager to BibleDB
moved content from BookNameDialog() from bibleimport.py in BibleDB.get_book_ref_id_by_name().
This commit is contained in:
parent
3d184f89a4
commit
a9c87798eb
@ -40,7 +40,6 @@ from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
|
||||
from openlp.core.utils import AppLocation, string_is_unicode
|
||||
from openlp.plugins.bibles.lib.manager import BibleFormat
|
||||
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
||||
from openlp.plugins.bibles.forms import BookNameForm
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -759,8 +758,3 @@ class BibleImportForm(OpenLPWizard):
|
||||
'BiblesPlugin.ImportWizardForm', 'Your Bible import failed.'))
|
||||
del self.manager.db_cache[importer.name]
|
||||
delete_database(self.plugin.settingsSection, importer.file)
|
||||
|
||||
def bookNameDialog(self, name):
|
||||
self.book_name = BookNameForm(self)
|
||||
if self.book_name.exec_(name):
|
||||
return unicode(self.book_name.requestComboBox.currentText())
|
||||
|
@ -25,7 +25,7 @@
|
||||
###############################################################################
|
||||
|
||||
"""
|
||||
Module implementing BookNameForm.
|
||||
Module implementing LanguageForm.
|
||||
"""
|
||||
import logging
|
||||
|
||||
|
@ -159,7 +159,7 @@ class CSVBible(BibleDB):
|
||||
self.wizard.incrementProgressBar(unicode(
|
||||
translate('BibleDB.Wizard', 'Importing books... %s')) %
|
||||
unicode(line[2], details['encoding']))
|
||||
book_ref_id = self.parent.manager.get_book_ref_id_by_name(
|
||||
book_ref_id = self.get_book_ref_id_by_name(
|
||||
unicode(line[2], details['encoding']), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s " '\
|
||||
|
@ -202,6 +202,8 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
Manager.__init__(self, u'bibles/bibles', init_schema, self.file)
|
||||
if u'file' in kwargs:
|
||||
self.get_name()
|
||||
if u'path' in kwargs:
|
||||
self.path = kwargs[u'path']
|
||||
self.wizard = None
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
|
||||
@ -383,6 +385,43 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
Book.book_reference_id.like(id))
|
||||
return db_book
|
||||
|
||||
def get_book_ref_id_by_name(self, book, language_id=None):
|
||||
log.debug(u'BibleManager.get_book_ref_id_by_name:("%s", "%s")', book,
|
||||
language_id)
|
||||
self.alternative_book_names_cache = AlternativeBookNamesDB(self.bible_plugin,
|
||||
path=self.path)
|
||||
if BiblesResourcesDB.get_book(book):
|
||||
book_temp = BiblesResourcesDB.get_book(book)
|
||||
book_id = book_temp[u'id']
|
||||
elif BiblesResourcesDB.get_alternative_book_name(book, language_id):
|
||||
book_id = BiblesResourcesDB.get_alternative_book_name(book,
|
||||
language_id)
|
||||
elif self.alternative_book_names_cache.get_book_reference_id(book,
|
||||
language_id):
|
||||
book_id = self.alternative_book_names_cache.get_book_reference_id(
|
||||
book, language_id)
|
||||
else:
|
||||
from openlp.plugins.bibles.forms import BookNameForm
|
||||
book_ref = None
|
||||
book_name = BookNameForm(self.wizard)
|
||||
if book_name.exec_(book):
|
||||
book_ref = unicode(book_name.requestComboBox.currentText())
|
||||
if not book_ref:
|
||||
return None
|
||||
else:
|
||||
book_temp = BiblesResourcesDB.get_book(book_ref)
|
||||
if book_temp:
|
||||
book_id = book_temp[u'id']
|
||||
else:
|
||||
return None
|
||||
if book_id:
|
||||
self.alternative_book_names_cache.create_alternative_book_name(
|
||||
book, book_id, language_id)
|
||||
if book_id:
|
||||
return book_id
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_verses(self, reference_list):
|
||||
"""
|
||||
This is probably the most used function. It retrieves the list of
|
||||
|
@ -424,8 +424,7 @@ class HTTPBible(BibleDB):
|
||||
self.wizard.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.HTTPBible', 'Importing %s...',
|
||||
'Importing <book name>...')) % book)
|
||||
book_ref_id = self.parent.manager.get_book_ref_id_by_name(book,
|
||||
language_id)
|
||||
book_ref_id = self.get_book_ref_id_by_name(book, language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s - download name: "%s" '\
|
||||
'failed' % (self.download_source, self.download_name))
|
||||
|
@ -33,8 +33,7 @@ from openlp.core.lib import Receiver, SettingsManager, translate
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.core.utils import AppLocation, delete_file
|
||||
from openlp.plugins.bibles.lib import parse_reference
|
||||
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, \
|
||||
AlternativeBookNamesDB, BiblesResourcesDB
|
||||
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta
|
||||
from csvbible import CSVBible
|
||||
from http import HTTPBible
|
||||
from opensong import OpenSongBible
|
||||
@ -170,19 +169,6 @@ class BibleManager(object):
|
||||
self.db_cache[name] = web_bible
|
||||
log.debug(u'Bibles reloaded')
|
||||
|
||||
#TODO: Delete unused code
|
||||
'''
|
||||
def reload_alternative_book_names(self):
|
||||
"""
|
||||
Reloads the alternative book names from the local alternative book names
|
||||
database on disk.
|
||||
"""
|
||||
log.debug(u'Reload AlternativeBookNames')
|
||||
self.alternative_book_names_cache = AlternativeBookNamesDB(self.parent,
|
||||
path=self.path)
|
||||
log.debug(u'AlternativeBookNames reloaded')
|
||||
'''
|
||||
|
||||
def set_process_dialog(self, wizard):
|
||||
"""
|
||||
Sets the reference to the dialog with the progress bar on it.
|
||||
@ -324,44 +310,6 @@ class BibleManager(object):
|
||||
})
|
||||
return None
|
||||
|
||||
def get_book_ref(self, book, language_id=None):
|
||||
log.debug(u'BibleManager.get_book_ref("%s", "%s")', book, language_id)
|
||||
book_id = self.get_book_ref_id_by_name(book, language_id)
|
||||
book_temp = BiblesResourcesDB.get_book_by_id(book_id)
|
||||
log.debug(u'BibleManager.get_book_ref("Return: %s")',
|
||||
book_temp[u'name'])
|
||||
return book_temp[u'name']
|
||||
|
||||
def get_book_ref_id_by_name(self, book, language_id=None):
|
||||
log.debug(u'BibleManager.get_book_ref_id_by_name:("%s", "%s")', book,
|
||||
language_id)
|
||||
self.alternative_book_names_cache = AlternativeBookNamesDB(self.parent,
|
||||
path=self.path)
|
||||
if BiblesResourcesDB.get_book(book):
|
||||
book_temp = BiblesResourcesDB.get_book(book)
|
||||
book_id = book_temp[u'id']
|
||||
elif BiblesResourcesDB.get_alternative_book_name(book, language_id):
|
||||
book_id = BiblesResourcesDB.get_alternative_book_name(book,
|
||||
language_id)
|
||||
elif self.alternative_book_names_cache.get_book_reference_id(book,
|
||||
language_id):
|
||||
book_id = self.alternative_book_names_cache.get_book_reference_id(
|
||||
book, language_id)
|
||||
else:
|
||||
book_ref = self.import_wizard.bookNameDialog(book)
|
||||
book_temp = BiblesResourcesDB.get_book(book_ref)
|
||||
if book_temp:
|
||||
book_id = book_temp[u'id']
|
||||
else:
|
||||
return None
|
||||
if book_id:
|
||||
self.alternative_book_names_cache.create_alternative_book_name(
|
||||
book, book_id, language_id)
|
||||
if book_id:
|
||||
return book_id
|
||||
else:
|
||||
return None
|
||||
|
||||
def verse_search(self, bible, second_bible, text):
|
||||
"""
|
||||
Does a verse search for the given bible and text.
|
||||
|
@ -75,8 +75,7 @@ class OpenLP1Bible(BibleDB):
|
||||
testament_id = int(book[1])
|
||||
name = unicode(book[2], u'cp1252')
|
||||
abbreviation = unicode(book[3], u'cp1252')
|
||||
book_ref_id = self.parent.manager.get_book_ref_id_by_name(name,
|
||||
language_id)
|
||||
book_ref_id = self.get_book_ref_id_by_name(name, language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s " '\
|
||||
'failed' % self.filename)
|
||||
|
@ -70,7 +70,7 @@ class OpenSongBible(BibleDB):
|
||||
for book in bible.b:
|
||||
if self.stop_import_flag:
|
||||
break
|
||||
book_ref_id = self.parent.manager.get_book_ref_id_by_name(
|
||||
book_ref_id = self.get_book_ref_id_by_name(
|
||||
unicode(book.attrib[u'n']), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s " '\
|
||||
|
@ -129,8 +129,7 @@ class OSISBible(BibleDB):
|
||||
#TODO: Delete unused code
|
||||
#if book == u'Matt' or book == u'Jdt':
|
||||
# testament += 1
|
||||
book_ref_id = self.parent.manager.\
|
||||
get_book_ref_id_by_name(
|
||||
book_ref_id = self.get_book_ref_id_by_name(
|
||||
unicode(self.books[book][0]), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s " '\
|
||||
|
Loading…
Reference in New Issue
Block a user