forked from openlp/openlp
rename spelling to alternative_book_name
This commit is contained in:
parent
a9b1fa2f5d
commit
27e635144d
@ -70,9 +70,9 @@ class Verse(BaseModel):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Spelling(BaseModel):
|
class AlternativeBookNames(BaseModel):
|
||||||
"""
|
"""
|
||||||
Spelling model
|
Alternative Book Names model
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -136,16 +136,17 @@ def init_schema(url):
|
|||||||
metadata.create_all(checkfirst=True)
|
metadata.create_all(checkfirst=True)
|
||||||
return session
|
return session
|
||||||
|
|
||||||
def init_schema_spelling_extension(url):
|
def init_schema_alternative_book_names(url):
|
||||||
"""
|
"""
|
||||||
Setup a spelling database connection and initialise the database schema.
|
Setup a alternative book names database connection and initialise the
|
||||||
|
database schema.
|
||||||
|
|
||||||
``url``
|
``url``
|
||||||
The database to setup.
|
The database to setup.
|
||||||
"""
|
"""
|
||||||
session, metadata = init_db(url)
|
session, metadata = init_db(url)
|
||||||
|
|
||||||
spelling_table = Table(u'spelling', metadata,
|
alternative_book_names_table = Table(u'alternative_book_names', metadata,
|
||||||
Column(u'id', types.Integer, primary_key=True),
|
Column(u'id', types.Integer, primary_key=True),
|
||||||
Column(u'book_reference_id', types.Integer),
|
Column(u'book_reference_id', types.Integer),
|
||||||
Column(u'language_id', types.Integer),
|
Column(u'language_id', types.Integer),
|
||||||
@ -153,9 +154,9 @@ def init_schema_spelling_extension(url):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
class_mapper(Spelling)
|
class_mapper(AlternativeBookNames)
|
||||||
except UnmappedClassError:
|
except UnmappedClassError:
|
||||||
mapper(Spelling, spelling_table)
|
mapper(AlternativeBookNames, alternative_book_names_table)
|
||||||
|
|
||||||
metadata.create_all(checkfirst=True)
|
metadata.create_all(checkfirst=True)
|
||||||
return session
|
return session
|
||||||
@ -508,7 +509,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
|||||||
A wrapper class around a small SQLite database which contains the download
|
A wrapper class around a small SQLite database which contains the download
|
||||||
resources, a biblelist from the different download resources, the books,
|
resources, a biblelist from the different download resources, the books,
|
||||||
chapter counts and verse counts for the web download Bibles, a language
|
chapter counts and verse counts for the web download Bibles, a language
|
||||||
reference, the testament reference and some basic spelling variants. This
|
reference, the testament reference and some alternative book names. This
|
||||||
class contains a singleton "cursor" so that only one connection to the
|
class contains a singleton "cursor" so that only one connection to the
|
||||||
SQLite database is ever used.
|
SQLite database is ever used.
|
||||||
"""
|
"""
|
||||||
@ -756,19 +757,20 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_spelling(name, language_id=None):
|
def get_alternative_book_name(name, language_id=None):
|
||||||
"""
|
"""
|
||||||
Return a book_reference_id if the name matches.
|
Return a book_reference_id if the name matches.
|
||||||
"""
|
"""
|
||||||
log.debug(u'BiblesResourcesDB.get_spelling("%s", "%s")', name,
|
log.debug(u'BiblesResourcesDB.get_alternative_book_name("%s", "%s")',
|
||||||
language_id)
|
name, language_id)
|
||||||
if language_id:
|
if language_id:
|
||||||
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id '
|
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id '
|
||||||
u'FROM spelling WHERE name = ? and language_id = ? ORDER BY id',
|
u'FROM alternative_book_names WHERE name = ? and language_id '
|
||||||
(name, language_id))
|
u'= ? ORDER BY id', (name, language_id))
|
||||||
else:
|
else:
|
||||||
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id '
|
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id '
|
||||||
u'FROM spelling WHERE name = ? ORDER BY id', (name, ))
|
u'FROM alternative_book_names WHERE name = ? ORDER BY id', (
|
||||||
|
name, ))
|
||||||
if id:
|
if id:
|
||||||
return int(id[0][0])
|
return int(id[0][0])
|
||||||
else:
|
else:
|
||||||
@ -834,9 +836,9 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
|||||||
})
|
})
|
||||||
return testament_list
|
return testament_list
|
||||||
|
|
||||||
class SpellingDB(QtCore.QObject, Manager):
|
class AlternativeBookNamesDB(QtCore.QObject, Manager):
|
||||||
"""
|
"""
|
||||||
This class represents a database-bound spelling.
|
This class represents a database-bound alternative book names system.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, parent, **kwargs):
|
def __init__(self, parent, **kwargs):
|
||||||
@ -853,18 +855,18 @@ class SpellingDB(QtCore.QObject, Manager):
|
|||||||
The name of the database. This is also used as the file name for
|
The name of the database. This is also used as the file name for
|
||||||
SQLite databases.
|
SQLite databases.
|
||||||
"""
|
"""
|
||||||
log.info(u'SpellingDB loaded')
|
log.info(u'AlternativeBookNamesDB loaded')
|
||||||
QtCore.QObject.__init__(self)
|
QtCore.QObject.__init__(self)
|
||||||
self.bible_plugin = parent
|
self.bible_plugin = parent
|
||||||
if u'path' not in kwargs:
|
if u'path' not in kwargs:
|
||||||
raise KeyError(u'Missing keyword argument "path".')
|
raise KeyError(u'Missing keyword argument "path".')
|
||||||
self.stop_import_flag = False
|
self.stop_import_flag = False
|
||||||
self.name = u'spelling_extension.sqlite'
|
self.name = u'alternative_book_names.sqlite'
|
||||||
if not isinstance(self.name, unicode):
|
if not isinstance(self.name, unicode):
|
||||||
self.name = unicode(self.name, u'utf-8')
|
self.name = unicode(self.name, u'utf-8')
|
||||||
self.file = self.name
|
self.file = self.name
|
||||||
Manager.__init__(self, u'bibles/resources',
|
Manager.__init__(self, u'bibles/resources',
|
||||||
init_schema_spelling_extension, self.file)
|
init_schema_alternative_book_names, self.file)
|
||||||
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)
|
||||||
@ -886,35 +888,36 @@ class SpellingDB(QtCore.QObject, Manager):
|
|||||||
``language``
|
``language``
|
||||||
The language for which should be searched
|
The language for which should be searched
|
||||||
"""
|
"""
|
||||||
log.debug(u'SpellingDB.get_book_reference_id("%s")', name)
|
log.debug(u'AlternativeBookNamesDB.get_book_reference_id("%s")', name)
|
||||||
if language:
|
if language:
|
||||||
id = self.session.query(Spelling.book_reference_id)\
|
id = self.session.query(AlternativeBookNames.book_reference_id)\
|
||||||
.filter(Spelling.name.like(name))\
|
.filter(AlternativeBookNames.name.like(name))\
|
||||||
.filter(Spelling.language_id.like(language)).first()
|
.filter(AlternativeBookNames.language_id.like(language)).first()
|
||||||
else:
|
else:
|
||||||
id = self.get_object_filtered(Spelling.book_reference_id,
|
id = self.get_object_filtered(AlternativeBookNames.book_reference_id,
|
||||||
Spelling.name.like(name))
|
AlternativeBookNames.name.like(name))
|
||||||
if not id:
|
if not id:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return id[0]
|
return id[0]
|
||||||
|
|
||||||
def create_spelling(self, name, book_reference_id, language_id):
|
def create_alternative_book_name(self, name, book_reference_id,
|
||||||
|
language_id):
|
||||||
"""
|
"""
|
||||||
Add a spelling to the database.
|
Add an alternative book name to the database.
|
||||||
|
|
||||||
``name``
|
``name``
|
||||||
The name of the spelling.
|
The name of the alternative book name.
|
||||||
|
|
||||||
``book_reference_id``
|
``book_reference_id``
|
||||||
The book_reference_id of the book.
|
The book_reference_id of the book.
|
||||||
|
|
||||||
``language_id``
|
``language_id``
|
||||||
The language which the spelling of the book name is.
|
The language to which the alternative book name belong.
|
||||||
"""
|
"""
|
||||||
log.debug(u'SpellingDBcreate_spelling("%s", "%s", "%s"',
|
log.debug(u'AlternativeBookNamesDB.create_alternative_book_name("%s", '
|
||||||
name, book_reference_id, language_id)
|
'"%s", "%s"', name, book_reference_id, language_id)
|
||||||
spelling = Spelling.populate(name=name,
|
alternative_book_name = AlternativeBookNames.populate(name=name,
|
||||||
book_reference_id=book_reference_id, language_id=language_id)
|
book_reference_id=book_reference_id, language_id=language_id)
|
||||||
self.save_object(spelling)
|
self.save_object(alternative_book_name)
|
||||||
return spelling
|
return alternative_book_name
|
||||||
|
@ -42,7 +42,7 @@ from openlp.core.lib.ui import critical_error_message_box
|
|||||||
from openlp.core.utils import AppLocation, get_web_page
|
from openlp.core.utils import AppLocation, get_web_page
|
||||||
from openlp.plugins.bibles.lib import SearchResults
|
from openlp.plugins.bibles.lib import SearchResults
|
||||||
from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB, \
|
from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB, \
|
||||||
SpellingDB, Book, BibleMeta
|
Book, BibleMeta
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ 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, SpellingDB, \
|
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, \
|
||||||
BiblesResourcesDB
|
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
|
||||||
@ -131,7 +131,7 @@ class BibleManager(object):
|
|||||||
self.suffix = u'.sqlite'
|
self.suffix = u'.sqlite'
|
||||||
self.import_wizard = None
|
self.import_wizard = None
|
||||||
self.reload_bibles()
|
self.reload_bibles()
|
||||||
self.reload_spelling()
|
self.reload_alternative_book_names()
|
||||||
self.media = None
|
self.media = None
|
||||||
|
|
||||||
def reload_bibles(self):
|
def reload_bibles(self):
|
||||||
@ -169,16 +169,15 @@ 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')
|
||||||
|
|
||||||
def reload_spelling(self):
|
def reload_alternative_book_names(self):
|
||||||
"""
|
"""
|
||||||
Reloads the Spelling from the Spelling table and spelling_extension
|
Reloads the alternative book names from the local alternative book names
|
||||||
database on disk.
|
database on disk.
|
||||||
"""
|
"""
|
||||||
log.debug(u'Reload spelling')
|
log.debug(u'Reload AlternativeBookNames')
|
||||||
self.spelling_cache = {}
|
self.alternative_book_names_cache = AlternativeBookNamesDB(self.parent,
|
||||||
self.spelling_cache[u'spelling'] = SpellingDB(self.parent,
|
|
||||||
path=self.path)
|
path=self.path)
|
||||||
log.debug(u'Spelling reloaded')
|
log.debug(u'AlternativeBookNames reloaded')
|
||||||
|
|
||||||
def set_process_dialog(self, wizard):
|
def set_process_dialog(self, wizard):
|
||||||
"""
|
"""
|
||||||
@ -335,12 +334,13 @@ class BibleManager(object):
|
|||||||
if BiblesResourcesDB.get_book(book):
|
if BiblesResourcesDB.get_book(book):
|
||||||
book_temp = BiblesResourcesDB.get_book(book)
|
book_temp = BiblesResourcesDB.get_book(book)
|
||||||
book_id = book_temp[u'id']
|
book_id = book_temp[u'id']
|
||||||
elif BiblesResourcesDB.get_spelling(book, language_id):
|
elif BiblesResourcesDB.get_alternative_book_name(book, language_id):
|
||||||
book_id = BiblesResourcesDB.get_spelling(book, language_id)
|
book_id = BiblesResourcesDB.get_alternative_book_name(book,
|
||||||
elif self.spelling_cache[u'spelling'].get_book_reference_id(book,
|
language_id)
|
||||||
|
elif self.alternative_book_names_cache.get_book_reference_id(book,
|
||||||
language_id):
|
language_id):
|
||||||
book_id = self.spelling_cache[u'spelling'].\
|
book_id = self.alternative_book_names_cache.get_book_reference_id(
|
||||||
get_book_reference_id(book, language_id)
|
book, language_id)
|
||||||
else:
|
else:
|
||||||
book_ref = self.parent.mediaItem.importRequest(u'book', book)
|
book_ref = self.parent.mediaItem.importRequest(u'book', book)
|
||||||
log.debug(book_ref)
|
log.debug(book_ref)
|
||||||
@ -351,8 +351,8 @@ class BibleManager(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
if book_id:
|
if book_id:
|
||||||
self.spelling_cache[u'spelling'].create_spelling(book, book_id,
|
self.alternative_book_names_cache.create_alternative_book_name(
|
||||||
language_id)
|
book, book_id, language_id)
|
||||||
if book_id:
|
if book_id:
|
||||||
return book_id
|
return book_id
|
||||||
else:
|
else:
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user