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:
Armin Köhler 2011-04-03 22:09:18 +02:00
parent 3d184f89a4
commit a9c87798eb
9 changed files with 46 additions and 68 deletions

View File

@ -40,7 +40,6 @@ from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.core.utils import AppLocation, string_is_unicode from openlp.core.utils import AppLocation, string_is_unicode
from openlp.plugins.bibles.lib.manager import BibleFormat from openlp.plugins.bibles.lib.manager import BibleFormat
from openlp.plugins.bibles.lib.db import BiblesResourcesDB from openlp.plugins.bibles.lib.db import BiblesResourcesDB
from openlp.plugins.bibles.forms import BookNameForm
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -759,8 +758,3 @@ class BibleImportForm(OpenLPWizard):
'BiblesPlugin.ImportWizardForm', 'Your Bible import failed.')) 'BiblesPlugin.ImportWizardForm', 'Your Bible import failed.'))
del self.manager.db_cache[importer.name] del self.manager.db_cache[importer.name]
delete_database(self.plugin.settingsSection, importer.file) 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())

View File

@ -25,7 +25,7 @@
############################################################################### ###############################################################################
""" """
Module implementing BookNameForm. Module implementing LanguageForm.
""" """
import logging import logging

View File

@ -159,7 +159,7 @@ class CSVBible(BibleDB):
self.wizard.incrementProgressBar(unicode( self.wizard.incrementProgressBar(unicode(
translate('BibleDB.Wizard', 'Importing books... %s')) % translate('BibleDB.Wizard', 'Importing books... %s')) %
unicode(line[2], details['encoding'])) 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) unicode(line[2], details['encoding']), language_id)
if not book_ref_id: if not book_ref_id:
log.exception(u'Importing books from %s " '\ log.exception(u'Importing books from %s " '\

View File

@ -202,6 +202,8 @@ class BibleDB(QtCore.QObject, Manager):
Manager.__init__(self, u'bibles/bibles', init_schema, self.file) Manager.__init__(self, u'bibles/bibles', init_schema, self.file)
if u'file' in kwargs: if u'file' in kwargs:
self.get_name() self.get_name()
if u'path' in kwargs:
self.path = kwargs[u'path']
self.wizard = None self.wizard = None
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
@ -383,6 +385,43 @@ class BibleDB(QtCore.QObject, Manager):
Book.book_reference_id.like(id)) Book.book_reference_id.like(id))
return db_book 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): def get_verses(self, 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

View File

@ -424,8 +424,7 @@ class HTTPBible(BibleDB):
self.wizard.incrementProgressBar(unicode(translate( self.wizard.incrementProgressBar(unicode(translate(
'BiblesPlugin.HTTPBible', 'Importing %s...', 'BiblesPlugin.HTTPBible', 'Importing %s...',
'Importing <book name>...')) % book) 'Importing <book name>...')) % book)
book_ref_id = self.parent.manager.get_book_ref_id_by_name(book, book_ref_id = self.get_book_ref_id_by_name(book, language_id)
language_id)
if not book_ref_id: if not book_ref_id:
log.exception(u'Importing books from %s - download name: "%s" '\ log.exception(u'Importing books from %s - download name: "%s" '\
'failed' % (self.download_source, self.download_name)) 'failed' % (self.download_source, self.download_name))

View File

@ -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.lib.ui import critical_error_message_box
from openlp.core.utils import AppLocation, delete_file from openlp.core.utils import AppLocation, delete_file
from openlp.plugins.bibles.lib import parse_reference from openlp.plugins.bibles.lib import parse_reference
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, \ from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta
AlternativeBookNamesDB, BiblesResourcesDB
from csvbible import CSVBible from csvbible import CSVBible
from http import HTTPBible from http import HTTPBible
from opensong import OpenSongBible from opensong import OpenSongBible
@ -170,19 +169,6 @@ class BibleManager(object):
self.db_cache[name] = web_bible self.db_cache[name] = web_bible
log.debug(u'Bibles reloaded') 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): def set_process_dialog(self, wizard):
""" """
Sets the reference to the dialog with the progress bar on it. Sets the reference to the dialog with the progress bar on it.
@ -324,44 +310,6 @@ class BibleManager(object):
}) })
return None 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): def verse_search(self, bible, second_bible, text):
""" """
Does a verse search for the given bible and text. Does a verse search for the given bible and text.

View File

@ -75,8 +75,7 @@ class OpenLP1Bible(BibleDB):
testament_id = int(book[1]) testament_id = int(book[1])
name = unicode(book[2], u'cp1252') name = unicode(book[2], u'cp1252')
abbreviation = unicode(book[3], u'cp1252') abbreviation = unicode(book[3], u'cp1252')
book_ref_id = self.parent.manager.get_book_ref_id_by_name(name, book_ref_id = self.get_book_ref_id_by_name(name, language_id)
language_id)
if not book_ref_id: if not book_ref_id:
log.exception(u'Importing books from %s " '\ log.exception(u'Importing books from %s " '\
'failed' % self.filename) 'failed' % self.filename)

View File

@ -70,7 +70,7 @@ class OpenSongBible(BibleDB):
for book in bible.b: for book in bible.b:
if self.stop_import_flag: if self.stop_import_flag:
break 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) unicode(book.attrib[u'n']), language_id)
if not book_ref_id: if not book_ref_id:
log.exception(u'Importing books from %s " '\ log.exception(u'Importing books from %s " '\

View File

@ -129,8 +129,7 @@ class OSISBible(BibleDB):
#TODO: Delete unused code #TODO: Delete unused code
#if book == u'Matt' or book == u'Jdt': #if book == u'Matt' or book == u'Jdt':
# testament += 1 # testament += 1
book_ref_id = self.parent.manager.\ book_ref_id = self.get_book_ref_id_by_name(
get_book_ref_id_by_name(
unicode(self.books[book][0]), language_id) unicode(self.books[book][0]), language_id)
if not book_ref_id: if not book_ref_id:
log.exception(u'Importing books from %s " '\ log.exception(u'Importing books from %s " '\