forked from openlp/openlp
Bibles
This commit is contained in:
parent
0da1b7b5f7
commit
83abc63079
@ -116,20 +116,20 @@ class BiblePlugin(Plugin):
|
||||
if QtGui.QMessageBox.information(self.main_window,
|
||||
translate('OpenLP', 'Information'),
|
||||
translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your existing Bibles.\n'
|
||||
'Should OpenLP upgrade now?'),
|
||||
'Should OpenLP upgrade now?'),
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == \
|
||||
QtGui.QMessageBox.Yes:
|
||||
self.on_tools_upgrade_Item_triggered()
|
||||
|
||||
def add_import_menu_item(self, import_menu):
|
||||
self.import_bible_item = create_action(import_menu, 'importBibleItem',
|
||||
text=translate('BiblesPlugin', '&Bible'), visible=False,
|
||||
triggers=self.on_bible_import_click)
|
||||
text=translate('BiblesPlugin', '&Bible'), visible=False,
|
||||
triggers=self.on_bible_import_click)
|
||||
import_menu.addAction(self.import_bible_item)
|
||||
|
||||
def add_export_menu_Item(self, export_menu):
|
||||
self.export_bible_item = create_action(export_menu, 'exportBibleItem',
|
||||
text=translate('BiblesPlugin', '&Bible'), visible=False)
|
||||
text=translate('BiblesPlugin', '&Bible'), visible=False)
|
||||
export_menu.addAction(self.export_bible_item)
|
||||
|
||||
def add_tools_menu_item(self, tools_menu):
|
||||
@ -140,7 +140,8 @@ class BiblePlugin(Plugin):
|
||||
The actual **Tools** menu item, so that your actions can use it as their parent.
|
||||
"""
|
||||
log.debug('add tools menu')
|
||||
self.tools_upgrade_item = create_action(tools_menu, 'toolsUpgradeItem',
|
||||
self.tools_upgrade_item = create_action(
|
||||
tools_menu, 'toolsUpgradeItem',
|
||||
text=translate('BiblesPlugin', '&Upgrade older Bibles'),
|
||||
statustip=translate('BiblesPlugin', 'Upgrade the Bible databases to the latest format.'),
|
||||
visible=False, triggers=self.on_tools_upgrade_Item_triggered)
|
||||
@ -162,14 +163,16 @@ class BiblePlugin(Plugin):
|
||||
|
||||
def about(self):
|
||||
about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>'
|
||||
'<br />The Bible plugin provides the ability to display Bible '
|
||||
'verses from different sources during the service.')
|
||||
'<br />The Bible plugin provides the ability to display Bible '
|
||||
'verses from different sources during the service.')
|
||||
return about_text
|
||||
|
||||
def uses_theme(self, theme):
|
||||
"""
|
||||
Called to find out if the bible plugin is currently using a theme. Returns ``True`` if the theme is being used,
|
||||
otherwise returns ``False``.
|
||||
|
||||
:param theme: The theme
|
||||
"""
|
||||
return str(self.settings_tab.bible_theme) == theme
|
||||
|
||||
@ -178,11 +181,8 @@ class BiblePlugin(Plugin):
|
||||
Rename the theme the bible plugin is using making the plugin use the
|
||||
new name.
|
||||
|
||||
``old_theme``
|
||||
The name of the theme the plugin should stop using. Unused for this particular plugin.
|
||||
|
||||
``new_theme``
|
||||
The new name the plugin should now use.
|
||||
:param old_theme: The name of the theme the plugin should stop using. Unused for this particular plugin.
|
||||
:param new_theme: The new name the plugin should now use.
|
||||
"""
|
||||
self.settings_tab.bible_theme = new_theme
|
||||
self.settings_tab.save()
|
||||
@ -207,8 +207,7 @@ class BiblePlugin(Plugin):
|
||||
'new': translate('BiblesPlugin', 'Add a new Bible.'),
|
||||
'edit': translate('BiblesPlugin', 'Edit the selected Bible.'),
|
||||
'delete': translate('BiblesPlugin', 'Delete the selected Bible.'),
|
||||
'preview': translate('BiblesPlugin',
|
||||
'Preview the selected Bible.'),
|
||||
'preview': translate('BiblesPlugin', 'Preview the selected Bible.'),
|
||||
'live': translate('BiblesPlugin', 'Send the selected Bible live.'),
|
||||
'service': translate('BiblesPlugin', 'Add the selected Bible to the service.')
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class BiblesTab(SettingsTab):
|
||||
self.end_separator_line_edit = QtGui.QLineEdit(self.scripture_reference_group_box)
|
||||
self.end_separator_line_edit.setObjectName('end_separator_line_edit')
|
||||
self.end_separator_line_edit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^0-9]*'),
|
||||
self.end_separator_line_edit))
|
||||
self.end_separator_line_edit))
|
||||
self.scripture_reference_layout.addWidget(self.end_separator_line_edit, 3, 1)
|
||||
self.left_layout.addWidget(self.scripture_reference_group_box)
|
||||
self.right_column.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
|
||||
@ -142,7 +142,7 @@ class BiblesTab(SettingsTab):
|
||||
self.new_chapters_check_box.stateChanged.connect(self.on_new_chapters_check_box_changed)
|
||||
self.display_style_combo_box.activated.connect(self.on_display_style_combo_box_changed)
|
||||
self.bible_theme_combo_box.activated.connect(self.on_bible_theme_combo_box_changed)
|
||||
self.layout_style_combo_box.activated.connect(self.on_layout_style_combo_boxChanged)
|
||||
self.layout_style_combo_box.activated.connect(self.on_layout_style_combo_box_changed)
|
||||
self.bible_second_check_box.stateChanged.connect(self.on_bible_second_check_box)
|
||||
self.verse_separator_check_box.clicked.connect(self.on_verse_separator_check_box_clicked)
|
||||
self.verse_separator_line_edit.textEdited.connect(self.on_verse_separator_line_edit_edited)
|
||||
@ -170,15 +170,15 @@ class BiblesTab(SettingsTab):
|
||||
self.layout_style_combo_box.setItemText(LayoutStyle.VersePerLine, UiStrings().VersePerLine)
|
||||
self.layout_style_combo_box.setItemText(LayoutStyle.Continuous, UiStrings().Continuous)
|
||||
self.display_style_combo_box.setItemText(DisplayStyle.NoBrackets,
|
||||
translate('BiblesPlugin.BiblesTab', 'No Brackets'))
|
||||
translate('BiblesPlugin.BiblesTab', 'No Brackets'))
|
||||
self.display_style_combo_box.setItemText(DisplayStyle.Round,
|
||||
translate('BiblesPlugin.BiblesTab', '( And )'))
|
||||
translate('BiblesPlugin.BiblesTab', '( And )'))
|
||||
self.display_style_combo_box.setItemText(DisplayStyle.Curly,
|
||||
translate('BiblesPlugin.BiblesTab', '{ And }'))
|
||||
translate('BiblesPlugin.BiblesTab', '{ And }'))
|
||||
self.display_style_combo_box.setItemText(DisplayStyle.Square,
|
||||
translate('BiblesPlugin.BiblesTab', '[ And ]'))
|
||||
translate('BiblesPlugin.BiblesTab', '[ And ]'))
|
||||
self.change_note_label.setText(translate('BiblesPlugin.BiblesTab',
|
||||
'Note:\nChanges do not affect verses already in the service.'))
|
||||
'Note:\nChanges do not affect verses already in the service.'))
|
||||
self.bible_second_check_box.setText(translate('BiblesPlugin.BiblesTab', 'Display second Bible verses'))
|
||||
self.scripture_reference_group_box.setTitle(translate('BiblesPlugin.BiblesTab', 'Custom Scripture References'))
|
||||
self.verse_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'Verse Separator:'))
|
||||
@ -186,21 +186,21 @@ class BiblesTab(SettingsTab):
|
||||
self.list_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'List Separator:'))
|
||||
self.end_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'End Mark:'))
|
||||
tip_text = translate('BiblesPlugin.BiblesTab',
|
||||
'Multiple alternative verse separators may be defined.\nThey have to be separated by a vertical bar "|".'
|
||||
'\nPlease clear this edit line to use the default value.')
|
||||
'Multiple alternative verse separators may be defined.\nThey have to be separated by a '
|
||||
'vertical bar "|".\nPlease clear this edit line to use the default value.')
|
||||
self.verse_separator_line_edit.setToolTip(tip_text)
|
||||
self.range_separator_line_edit.setToolTip(tip_text)
|
||||
self.list_separator_line_edit.setToolTip(tip_text)
|
||||
self.end_separator_line_edit.setToolTip(tip_text)
|
||||
self.language_selection_group_box.setTitle(translate('BiblesPlugin.BiblesTab', 'Default Bible Language'))
|
||||
self.language_selection_label.setText(translate('BiblesPlugin.BiblesTab',
|
||||
'Book name language in search field,\nsearch results and on display:'))
|
||||
self.language_selection_combo_box.setItemText(LanguageSelection.Bible,
|
||||
translate('BiblesPlugin.BiblesTab', 'Bible Language'))
|
||||
self.language_selection_combo_box.setItemText(LanguageSelection.Application,
|
||||
translate('BiblesPlugin.BiblesTab', 'Application Language'))
|
||||
self.language_selection_combo_box.setItemText(LanguageSelection.English,
|
||||
translate('BiblesPlugin.BiblesTab', 'English'))
|
||||
self.language_selection_label.setText(
|
||||
translate('BiblesPlugin.BiblesTab', 'Book name language in search field,\nsearch results and on display:'))
|
||||
self.language_selection_combo_box.setItemText(
|
||||
LanguageSelection.Bible, translate('BiblesPlugin.BiblesTab', 'Bible Language'))
|
||||
self.language_selection_combo_box.setItemText(
|
||||
LanguageSelection.Application, translate('BiblesPlugin.BiblesTab', 'Application Language'))
|
||||
self.language_selection_combo_box.setItemText(
|
||||
LanguageSelection.English, translate('BiblesPlugin.BiblesTab', 'English'))
|
||||
|
||||
def on_bible_theme_combo_box_changed(self):
|
||||
self.bible_theme = self.bible_theme_combo_box.currentText()
|
||||
@ -208,7 +208,7 @@ class BiblesTab(SettingsTab):
|
||||
def on_display_style_combo_box_changed(self):
|
||||
self.display_style = self.display_style_combo_box.currentIndex()
|
||||
|
||||
def on_layout_style_combo_boxChanged(self):
|
||||
def on_layout_style_combo_box_changed(self):
|
||||
self.layout_style = self.layout_style_combo_box.currentIndex()
|
||||
|
||||
def on_language_selection_combo_box_changed(self):
|
||||
@ -238,11 +238,11 @@ class BiblesTab(SettingsTab):
|
||||
self.verse_separator_line_edit.setFocus()
|
||||
else:
|
||||
self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
|
||||
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(not checked))
|
||||
self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
|
||||
|
||||
def on_verse_separator_line_edit_edited(self, text):
|
||||
self.verse_separator_check_box.setChecked(True)
|
||||
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
|
||||
def on_verse_separator_line_edit_finished(self):
|
||||
if self.verse_separator_line_edit.isModified():
|
||||
@ -250,18 +250,18 @@ class BiblesTab(SettingsTab):
|
||||
if text == get_reference_separator('sep_v_default') or not text.replace('|', ''):
|
||||
self.verse_separator_check_box.setChecked(False)
|
||||
self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
|
||||
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
|
||||
def on_range_separator_check_box_clicked(self, checked):
|
||||
if checked:
|
||||
self.range_separator_line_edit.setFocus()
|
||||
else:
|
||||
self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
|
||||
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(not checked))
|
||||
self.range_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
|
||||
|
||||
def on_range_separator_line_edit_edited(self, text):
|
||||
self.range_separator_check_box.setChecked(True)
|
||||
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.range_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
|
||||
def on_range_separator_line_edit_finished(self):
|
||||
if self.range_separator_line_edit.isModified():
|
||||
@ -269,18 +269,18 @@ class BiblesTab(SettingsTab):
|
||||
if text == get_reference_separator('sep_r_default') or not text.replace('|', ''):
|
||||
self.range_separator_check_box.setChecked(False)
|
||||
self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
|
||||
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.range_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
|
||||
def on_list_separator_check_box_clicked(self, checked):
|
||||
if checked:
|
||||
self.list_separator_line_edit.setFocus()
|
||||
else:
|
||||
self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
|
||||
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(not checked))
|
||||
self.list_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
|
||||
|
||||
def on_list_separator_line_edit_edited(self, text):
|
||||
self.list_separator_check_box.setChecked(True)
|
||||
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.list_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
|
||||
def on_list_separator_line_edit_finished(self):
|
||||
if self.list_separator_line_edit.isModified():
|
||||
@ -288,18 +288,18 @@ class BiblesTab(SettingsTab):
|
||||
if text == get_reference_separator('sep_l_default') or not text.replace('|', ''):
|
||||
self.list_separator_check_box.setChecked(False)
|
||||
self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
|
||||
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.list_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
|
||||
def on_end_separator_check_box_clicked(self, checked):
|
||||
if checked:
|
||||
self.end_separator_line_edit.setFocus()
|
||||
else:
|
||||
self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
|
||||
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(not checked))
|
||||
self.end_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
|
||||
|
||||
def on_end_separator_line_edit_edited(self, text):
|
||||
self.end_separator_check_box.setChecked(True)
|
||||
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.end_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
|
||||
def on_end_separator_line_edit_finished(self):
|
||||
if self.end_separator_line_edit.isModified():
|
||||
@ -307,7 +307,7 @@ class BiblesTab(SettingsTab):
|
||||
if text == get_reference_separator('sep_e_default') or not text.replace('|', ''):
|
||||
self.end_separator_check_box.setChecked(False)
|
||||
self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
|
||||
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
|
||||
def load(self):
|
||||
settings = Settings()
|
||||
@ -327,38 +327,38 @@ class BiblesTab(SettingsTab):
|
||||
verse_separator = settings.value('verse separator')
|
||||
if (verse_separator.strip('|') == '') or (verse_separator == get_reference_separator('sep_v_default')):
|
||||
self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
|
||||
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
self.verse_separator_check_box.setChecked(False)
|
||||
else:
|
||||
self.verse_separator_line_edit.setText(verse_separator)
|
||||
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
self.verse_separator_check_box.setChecked(True)
|
||||
range_separator = settings.value('range separator')
|
||||
if (range_separator.strip('|') == '') or (range_separator == get_reference_separator('sep_r_default')):
|
||||
self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
|
||||
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.range_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
self.range_separator_check_box.setChecked(False)
|
||||
else:
|
||||
self.range_separator_line_edit.setText(range_separator)
|
||||
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.range_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
self.range_separator_check_box.setChecked(True)
|
||||
list_separator = settings.value('list separator')
|
||||
if (list_separator.strip('|') == '') or (list_separator == get_reference_separator('sep_l_default')):
|
||||
self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
|
||||
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.list_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
self.list_separator_check_box.setChecked(False)
|
||||
else:
|
||||
self.list_separator_line_edit.setText(list_separator)
|
||||
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.list_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
self.list_separator_check_box.setChecked(True)
|
||||
end_separator = settings.value('end separator')
|
||||
if (end_separator.strip('|') == '') or (end_separator == get_reference_separator('sep_e_default')):
|
||||
self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
|
||||
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(True))
|
||||
self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
|
||||
self.end_separator_check_box.setChecked(False)
|
||||
else:
|
||||
self.end_separator_line_edit.setText(end_separator)
|
||||
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(False))
|
||||
self.end_separator_line_edit.setPalette(self.get_grey_text_palette(False))
|
||||
self.end_separator_check_box.setChecked(True)
|
||||
self.language_selection = settings.value('book name language')
|
||||
self.language_selection_combo_box.setCurrentIndex(self.language_selection)
|
||||
@ -402,7 +402,7 @@ class BiblesTab(SettingsTab):
|
||||
"""
|
||||
Called from ThemeManager when the Themes have changed.
|
||||
|
||||
``theme_list``
|
||||
:param theme_list:
|
||||
The list of available themes::
|
||||
|
||||
[u'Bible Theme', u'Song Theme']
|
||||
@ -412,7 +412,7 @@ class BiblesTab(SettingsTab):
|
||||
self.bible_theme_combo_box.addItems(theme_list)
|
||||
find_and_set_in_combo_box(self.bible_theme_combo_box, self.bible_theme)
|
||||
|
||||
def getGreyTextPalette(self, greyed):
|
||||
def get_grey_text_palette(self, greyed):
|
||||
"""
|
||||
Returns a QPalette with greyed out text as used for placeholderText.
|
||||
"""
|
||||
|
@ -80,8 +80,8 @@ class CSVBible(BibleDB):
|
||||
"""
|
||||
log.info(self.__class__.__name__)
|
||||
BibleDB.__init__(self, parent, **kwargs)
|
||||
self.booksfile = kwargs['booksfile']
|
||||
self.versesfile = kwargs['versefile']
|
||||
self.books_file = kwargs['books_file']
|
||||
self.verses_file = kwargs['versefile']
|
||||
|
||||
def do_import(self, bible_name=None):
|
||||
"""
|
||||
@ -99,8 +99,8 @@ class CSVBible(BibleDB):
|
||||
book_list = {}
|
||||
# Populate the Tables
|
||||
try:
|
||||
details = get_file_encoding(self.booksfile)
|
||||
books_file = open(self.booksfile, 'r')
|
||||
details = get_file_encoding(self.books_file)
|
||||
books_file = open(self.books_file, 'r')
|
||||
if not books_file.read(3) == '\xEF\xBB\xBF':
|
||||
# no BOM was found
|
||||
books_file.seek(0)
|
||||
@ -109,10 +109,10 @@ class CSVBible(BibleDB):
|
||||
if self.stop_import_flag:
|
||||
break
|
||||
self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible', 'Importing books... %s') %
|
||||
str(line[2], details['encoding']))
|
||||
str(line[2], details['encoding']))
|
||||
book_ref_id = self.get_book_ref_id_by_name(str(line[2], details['encoding']), 67, language_id)
|
||||
if not book_ref_id:
|
||||
log.error('Importing books from "%s" failed' % self.booksfile)
|
||||
log.error('Importing books from "%s" failed' % self.books_file)
|
||||
return False
|
||||
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||
self.create_book(str(line[2], details['encoding']), book_ref_id, book_details['testament_id'])
|
||||
@ -131,8 +131,8 @@ class CSVBible(BibleDB):
|
||||
verse_file = None
|
||||
try:
|
||||
book_ptr = None
|
||||
details = get_file_encoding(self.versesfile)
|
||||
verse_file = open(self.versesfile, 'rb')
|
||||
details = get_file_encoding(self.verses_file)
|
||||
verse_file = open(self.verses_file, 'rb')
|
||||
if not verse_file.read(3) == '\xEF\xBB\xBF':
|
||||
# no BOM was found
|
||||
verse_file.seek(0)
|
||||
@ -147,8 +147,9 @@ class CSVBible(BibleDB):
|
||||
if book_ptr != line_book:
|
||||
book = self.get_book(line_book)
|
||||
book_ptr = book.name
|
||||
self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible',
|
||||
'Importing verses from %s... Importing verses from <book name>...') % book.name)
|
||||
self.wizard.increment_progress_bar(
|
||||
translate('BiblesPlugin.CSVBible',
|
||||
'Importing verses from %s... Importing verses from <book name>...') % book.name)
|
||||
self.session.commit()
|
||||
try:
|
||||
verse_text = str(line[3], details['encoding'])
|
||||
@ -169,6 +170,7 @@ class CSVBible(BibleDB):
|
||||
else:
|
||||
return success
|
||||
|
||||
|
||||
def get_file_encoding(filename):
|
||||
"""
|
||||
Utility function to get the file encoding.
|
||||
|
@ -79,23 +79,23 @@ def init_schema(url):
|
||||
session, metadata = init_db(url)
|
||||
|
||||
meta_table = Table('metadata', metadata,
|
||||
Column('key', types.Unicode(255), primary_key=True, index=True),
|
||||
Column('value', types.Unicode(255)),
|
||||
Column('key', types.Unicode(255), primary_key=True, index=True),
|
||||
Column('value', types.Unicode(255)),
|
||||
)
|
||||
|
||||
book_table = Table('book', metadata,
|
||||
Column('id', types.Integer, primary_key=True),
|
||||
Column('book_reference_id', types.Integer, index=True),
|
||||
Column('testament_reference_id', types.Integer),
|
||||
Column('name', types.Unicode(50), index=True),
|
||||
Column('id', types.Integer, primary_key=True),
|
||||
Column('book_reference_id', types.Integer, index=True),
|
||||
Column('testament_reference_id', types.Integer),
|
||||
Column('name', types.Unicode(50), index=True),
|
||||
)
|
||||
verse_table = Table('verse', metadata,
|
||||
Column('id', types.Integer, primary_key=True, index=True),
|
||||
Column('book_id', types.Integer, ForeignKey(
|
||||
'book.id'), index=True),
|
||||
Column('chapter', types.Integer, index=True),
|
||||
Column('verse', types.Integer, index=True),
|
||||
Column('text', types.UnicodeText, index=True),
|
||||
Column('id', types.Integer, primary_key=True, index=True),
|
||||
Column('book_id', types.Integer, ForeignKey(
|
||||
'book.id'), index=True),
|
||||
Column('chapter', types.Integer, index=True),
|
||||
Column('verse', types.Integer, index=True),
|
||||
Column('text', types.UnicodeText, index=True),
|
||||
)
|
||||
|
||||
try:
|
||||
@ -105,8 +105,7 @@ def init_schema(url):
|
||||
try:
|
||||
class_mapper(Book)
|
||||
except UnmappedClassError:
|
||||
mapper(Book, book_table,
|
||||
properties={'verses': relation(Verse, backref='book')})
|
||||
mapper(Book, book_table, properties={'verses': relation(Verse, backref='book')})
|
||||
try:
|
||||
class_mapper(Verse)
|
||||
except UnmappedClassError:
|
||||
@ -184,8 +183,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
may want to override this method to supply their own custom
|
||||
initialisation as well.
|
||||
|
||||
``wizard``
|
||||
The actual Qt wizard form.
|
||||
:param wizard: The actual Qt wizard form.
|
||||
"""
|
||||
self.wizard = wizard
|
||||
return self.name
|
||||
@ -194,14 +192,9 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Add a book to the database.
|
||||
|
||||
``name``
|
||||
The name of the book.
|
||||
|
||||
``bk_ref_id``
|
||||
The book_reference_id from bibles_resources.sqlite of the book.
|
||||
|
||||
``testament``
|
||||
*Defaults to 1.* The testament_reference_id from
|
||||
:param name: The name of the book.
|
||||
:param bk_ref_id: The book_reference_id from bibles_resources.sqlite of the book.
|
||||
:param testament: *Defaults to 1.* The testament_reference_id from
|
||||
bibles_resources.sqlite of the testament this book belongs to.
|
||||
"""
|
||||
log.debug('BibleDB.create_book("%s", "%s")', name, bk_ref_id)
|
||||
@ -213,8 +206,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Update a book in the database.
|
||||
|
||||
``book``
|
||||
The book object
|
||||
:param book: The book object
|
||||
"""
|
||||
log.debug('BibleDB.update_book("%s")', book.name)
|
||||
return self.save_object(book)
|
||||
@ -223,31 +215,24 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Delete a book from the database.
|
||||
|
||||
``db_book``
|
||||
The book object.
|
||||
:param db_book: The book object.
|
||||
"""
|
||||
log.debug('BibleDB.delete_book("%s")', db_book.name)
|
||||
if self.delete_object(Book, db_book.id):
|
||||
return True
|
||||
return False
|
||||
|
||||
def create_chapter(self, book_id, chapter, textlist):
|
||||
def create_chapter(self, book_id, chapter, text_list):
|
||||
"""
|
||||
Add a chapter and its verses to a book.
|
||||
|
||||
``book_id``
|
||||
The id of the book being appended.
|
||||
|
||||
``chapter``
|
||||
The chapter number.
|
||||
|
||||
``textlist``
|
||||
A dict of the verses to be inserted. The key is the verse number,
|
||||
and the value is the verse text.
|
||||
:param book_id: The id of the book being appended.
|
||||
:param chapter: The chapter number.
|
||||
:param text_list: A dict of the verses to be inserted. The key is the verse number, and the value is the verse text.
|
||||
"""
|
||||
log.debug('BibleDBcreate_chapter("%s", "%s")', book_id, chapter)
|
||||
# Text list has book and chapter as first two elements of the array.
|
||||
for verse_number, verse_text in textlist.items():
|
||||
for verse_number, verse_text in text_list.items():
|
||||
verse = Verse.populate(
|
||||
book_id=book_id,
|
||||
chapter=chapter,
|
||||
@ -261,17 +246,10 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Add a single verse to a chapter.
|
||||
|
||||
``book_id``
|
||||
The id of the book being appended.
|
||||
|
||||
``chapter``
|
||||
The chapter number.
|
||||
|
||||
``verse``
|
||||
The verse number.
|
||||
|
||||
``text``
|
||||
The verse text.
|
||||
:param book_id: The id of the book being appended.
|
||||
:param chapter: The chapter number.
|
||||
:param verse: The verse number.
|
||||
:param text: The verse text.
|
||||
"""
|
||||
if not isinstance(text, str):
|
||||
details = chardet.detect(text)
|
||||
@ -289,11 +267,8 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Utility method to save or update BibleMeta objects in a Bible database.
|
||||
|
||||
``key``
|
||||
The key for this instance.
|
||||
|
||||
``value``
|
||||
The value for this instance.
|
||||
:param key: The key for this instance.
|
||||
:param value: The value for this instance.
|
||||
"""
|
||||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
@ -309,8 +284,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book object from the database.
|
||||
|
||||
``book``
|
||||
The name of the book to return.
|
||||
:param book: The name of the book to return.
|
||||
"""
|
||||
log.debug('BibleDB.get_book("%s")', book)
|
||||
return self.get_object_filtered(Book, Book.name.like(book + '%'))
|
||||
@ -327,8 +301,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book object from the database.
|
||||
|
||||
``id``
|
||||
The reference id of the book to return.
|
||||
:param id: The reference id of the book to return.
|
||||
"""
|
||||
log.debug('BibleDB.get_book_by_book_ref_id("%s")', id)
|
||||
return self.get_object_filtered(Book, Book.book_reference_id.like(id))
|
||||
@ -357,11 +330,8 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the id of a named book.
|
||||
|
||||
``book``
|
||||
The name of the book, according to the selected language.
|
||||
|
||||
``language_selection``
|
||||
The language selection the user has chosen in the settings section of the Bible.
|
||||
:param book: The name of the book, according to the selected language.
|
||||
:param language_selection: The language selection the user has chosen in the settings section of the Bible.
|
||||
"""
|
||||
log.debug('get_book_ref_id_by_localised_name("%s", "%s")', book, language_selection)
|
||||
from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
|
||||
@ -398,8 +368,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
This is probably the most used function. It retrieves the list of
|
||||
verses based on the user's query.
|
||||
|
||||
``reference_list``
|
||||
This is the list of references the media manager item wants. It is
|
||||
:param reference_list: This is the list of references the media manager item wants. It is
|
||||
a list of tuples, with the following format::
|
||||
|
||||
(book_reference_id, chapter, start_verse, end_verse)
|
||||
@ -410,6 +379,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
list of ``Verse`` objects. For example::
|
||||
|
||||
[(u'35', 1, 1, 1), (u'35', 2, 2, 3)]
|
||||
:param show_error:
|
||||
"""
|
||||
log.debug('BibleDB.get_verses("%s")', reference_list)
|
||||
verse_list = []
|
||||
@ -436,14 +406,14 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin', 'No Book Found'),
|
||||
translate('BiblesPlugin', 'No matching book '
|
||||
'could be found in this Bible. Check that you have spelled the name of the book correctly.'))
|
||||
'could be found in this Bible. Check that you have spelled the name of the book correctly.'))
|
||||
return verse_list
|
||||
|
||||
def verse_search(self, text):
|
||||
"""
|
||||
Search for verses containing text ``text``.
|
||||
|
||||
``text``
|
||||
:param text:
|
||||
The text to search for. If the text contains commas, it will be
|
||||
split apart and OR'd on the list of values. If the text just
|
||||
contains spaces, it will split apart and AND'd on the list of
|
||||
@ -468,8 +438,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the number of chapters in a book.
|
||||
|
||||
``book``
|
||||
The book object to get the chapter count for.
|
||||
:param book: The book object to get the chapter count for.
|
||||
"""
|
||||
log.debug('BibleDB.get_chapter_count("%s")', book.name)
|
||||
count = self.session.query(func.max(Verse.chapter)).join(Book).filter(
|
||||
@ -482,11 +451,8 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the number of verses in a chapter.
|
||||
|
||||
``book_ref_id``
|
||||
The book reference id.
|
||||
|
||||
``chapter``
|
||||
The chapter to get the verse count for.
|
||||
:param book_ref_id: The book reference id.
|
||||
:param chapter: The chapter to get the verse count for.
|
||||
"""
|
||||
log.debug('BibleDB.get_verse_count("%s", "%s")', book_ref_id, chapter)
|
||||
count = self.session.query(func.max(Verse.verse)).join(Book) \
|
||||
@ -499,12 +465,10 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def get_language(self, bible_name=None):
|
||||
"""
|
||||
If no language is given it calls a dialog window where the user could
|
||||
select the bible language.
|
||||
If no language is given it calls a dialog window where the user could select the bible language.
|
||||
Return the language id of a bible.
|
||||
|
||||
``book``
|
||||
The language the bible is.
|
||||
:param bible_name: The language the bible is.
|
||||
"""
|
||||
log.debug('BibleDB.get_language()')
|
||||
from openlp.plugins.bibles.forms import LanguageForm
|
||||
@ -521,8 +485,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def is_old_database(self):
|
||||
"""
|
||||
Returns ``True`` if it is a bible database, which has been created
|
||||
prior to 1.9.6.
|
||||
Returns ``True`` if it is a bible database, which has been created prior to 1.9.6.
|
||||
"""
|
||||
try:
|
||||
self.session.query(Book).all()
|
||||
@ -576,9 +539,9 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
Return the cursor object. Instantiate one if it doesn't exist yet.
|
||||
"""
|
||||
if BiblesResourcesDB.cursor is None:
|
||||
filepath = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir),
|
||||
'bibles', 'resources', 'bibles_resources.sqlite')
|
||||
conn = sqlite3.connect(filepath)
|
||||
file_path = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir),
|
||||
'bibles', 'resources', 'bibles_resources.sqlite')
|
||||
conn = sqlite3.connect(file_path)
|
||||
BiblesResourcesDB.cursor = conn.cursor()
|
||||
return BiblesResourcesDB.cursor
|
||||
|
||||
@ -603,8 +566,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
Return a list of all the books of the Bible.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_books()')
|
||||
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, '
|
||||
'abbreviation, chapters FROM book_reference ORDER BY id')
|
||||
books = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference ORDER BY id')
|
||||
return [{
|
||||
'id': book[0],
|
||||
'testament_id': book[1],
|
||||
@ -618,24 +581,20 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book by name or abbreviation.
|
||||
|
||||
``name``
|
||||
The name or abbreviation of the book.
|
||||
|
||||
``lower``
|
||||
True if the comparsion should be only lowercase
|
||||
:param name: The name or abbreviation of the book.
|
||||
:param lower: True if the comparsion should be only lowercase
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_book("%s")', name)
|
||||
if not isinstance(name, str):
|
||||
name = str(name)
|
||||
if lower:
|
||||
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, '
|
||||
'abbreviation, chapters FROM book_reference WHERE '
|
||||
'LOWER(name) = ? OR LOWER(abbreviation) = ?',
|
||||
(name.lower(), name.lower()))
|
||||
books = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE '
|
||||
'LOWER(name) = ? OR LOWER(abbreviation) = ?', (name.lower(), name.lower()))
|
||||
else:
|
||||
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, '
|
||||
'abbreviation, chapters FROM book_reference WHERE name = ?'
|
||||
' OR abbreviation = ?', (name, name))
|
||||
books = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE name = ?'
|
||||
' OR abbreviation = ?', (name, name))
|
||||
if books:
|
||||
return {
|
||||
'id': books[0][0],
|
||||
@ -652,16 +611,15 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the books which include string.
|
||||
|
||||
``string``
|
||||
The string to search for in the book names or abbreviations.
|
||||
:param string: The string to search for in the book names or abbreviations.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_book_like("%s")', string)
|
||||
if not isinstance(string, str):
|
||||
name = str(string)
|
||||
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, '
|
||||
'abbreviation, chapters FROM book_reference WHERE '
|
||||
'LOWER(name) LIKE ? OR LOWER(abbreviation) LIKE ?',
|
||||
('%' + string.lower() + '%', '%' + string.lower() + '%'))
|
||||
books = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE '
|
||||
'LOWER(name) LIKE ? OR LOWER(abbreviation) LIKE ?',
|
||||
('%' + string.lower() + '%', '%' + string.lower() + '%'))
|
||||
if books:
|
||||
return [{
|
||||
'id': book[0],
|
||||
@ -678,14 +636,13 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book by id.
|
||||
|
||||
``id``
|
||||
The id of the book.
|
||||
:param id: The id of the book.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_book_by_id("%s")', id)
|
||||
if not isinstance(id, int):
|
||||
id = int(id)
|
||||
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, '
|
||||
'abbreviation, chapters FROM book_reference WHERE id = ?', (id, ))
|
||||
books = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE id = ?', (id, ))
|
||||
if books:
|
||||
return {
|
||||
'id': books[0][0],
|
||||
@ -702,16 +659,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the chapter details for a specific chapter of a book.
|
||||
|
||||
``book_ref_id``
|
||||
The id of a book.
|
||||
|
||||
``chapter``
|
||||
The chapter number.
|
||||
:param book_ref_id: The id of a book.
|
||||
:param chapter: The chapter number.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_chapter("%s", "%s")', book_ref_id, chapter)
|
||||
if not isinstance(chapter, int):
|
||||
chapter = int(chapter)
|
||||
chapters = BiblesResourcesDB.run_sql('SELECT id, book_reference_id, '
|
||||
chapters = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, book_reference_id, '
|
||||
'chapter, verse_count FROM chapters WHERE book_reference_id = ?', (book_ref_id,))
|
||||
try:
|
||||
return {
|
||||
@ -728,8 +683,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the number of chapters in a book.
|
||||
|
||||
``book_ref_id``
|
||||
The id of the book.
|
||||
:param book_ref_id: The id of the book.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_chapter_count("%s")', book_ref_id)
|
||||
details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||
@ -742,11 +696,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the number of verses in a chapter.
|
||||
|
||||
``book``
|
||||
The id of the book.
|
||||
|
||||
``chapter``
|
||||
The number of the chapter.
|
||||
:param book_ref_id: The id of the book.
|
||||
:param chapter: The number of the chapter.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_verse_count("%s", "%s")', book_ref_id, chapter)
|
||||
details = BiblesResourcesDB.get_chapter(book_ref_id, chapter)
|
||||
@ -759,15 +710,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a download_source_id by source.
|
||||
|
||||
``name``
|
||||
The name or abbreviation of the book.
|
||||
:param source: The name or abbreviation of the book.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_download_source("%s")', source)
|
||||
if not isinstance(source, str):
|
||||
source = str(source)
|
||||
source = source.title()
|
||||
dl_source = BiblesResourcesDB.run_sql('SELECT id, source FROM '
|
||||
'download_source WHERE source = ?', (source.lower(),))
|
||||
dl_source = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, source FROM download_source WHERE source = ?', (source.lower(),))
|
||||
if dl_source:
|
||||
return {
|
||||
'id': dl_source[0][0],
|
||||
@ -781,8 +731,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the bibles a webbible provide for download.
|
||||
|
||||
``source``
|
||||
The source of the webbible.
|
||||
:param source: The source of the webbible.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_webbibles("%s")', source)
|
||||
if not isinstance(source, str):
|
||||
@ -806,11 +755,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return the bibles a webbible provide for download.
|
||||
|
||||
``abbreviation``
|
||||
The abbreviation of the webbible.
|
||||
|
||||
``source``
|
||||
The source of the webbible.
|
||||
:param abbreviation: The abbreviation of the webbible.
|
||||
:param source: The source of the webbible.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_webbibles("%s", "%s")', abbreviation, source)
|
||||
if not isinstance(abbreviation, str):
|
||||
@ -818,8 +764,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
if not isinstance(source, str):
|
||||
source = str(source)
|
||||
source = BiblesResourcesDB.get_download_source(source)
|
||||
bible = BiblesResourcesDB.run_sql('SELECT id, name, abbreviation, '
|
||||
'language_id, download_source_id FROM webbibles WHERE '
|
||||
bible = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, name, abbreviation, language_id, download_source_id FROM webbibles WHERE '
|
||||
'download_source_id = ? AND abbreviation = ?', (source['id'], abbreviation))
|
||||
try:
|
||||
return {
|
||||
@ -837,16 +783,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book_reference_id if the name matches.
|
||||
|
||||
``name``
|
||||
The name to search the id.
|
||||
|
||||
``language_id``
|
||||
The language_id for which language should be searched
|
||||
:param name: The name to search the id.
|
||||
:param language_id: The language_id for which language should be searched
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_alternative_book_name("%s", "%s")', name, language_id)
|
||||
if language_id:
|
||||
books = BiblesResourcesDB.run_sql('SELECT book_reference_id, name '
|
||||
'FROM alternative_book_names WHERE language_id = ? ORDER BY id', (language_id, ))
|
||||
books = BiblesResourcesDB.run_sql(
|
||||
'SELECT book_reference_id, name FROM alternative_book_names WHERE language_id = ? ORDER BY id',
|
||||
(language_id, ))
|
||||
else:
|
||||
books = BiblesResourcesDB.run_sql('SELECT book_reference_id, name FROM alternative_book_names ORDER BY id')
|
||||
for book in books:
|
||||
@ -857,17 +801,15 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
@staticmethod
|
||||
def get_language(name):
|
||||
"""
|
||||
Return a dict containing the language id, name and code by name or
|
||||
abbreviation.
|
||||
Return a dict containing the language id, name and code by name or abbreviation.
|
||||
|
||||
``name``
|
||||
The name or abbreviation of the language.
|
||||
:param name: The name or abbreviation of the language.
|
||||
"""
|
||||
log.debug('BiblesResourcesDB.get_language("%s")', name)
|
||||
if not isinstance(name, str):
|
||||
name = str(name)
|
||||
language = BiblesResourcesDB.run_sql('SELECT id, name, code FROM '
|
||||
'language WHERE name = ? OR code = ?', (name, name.lower()))
|
||||
language = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, name, code FROM language WHERE name = ? OR code = ?', (name, name.lower()))
|
||||
if language:
|
||||
return {
|
||||
'id': language[0][0],
|
||||
@ -920,22 +862,20 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
|
||||
def get_cursor():
|
||||
"""
|
||||
Return the cursor object. Instantiate one if it doesn't exist yet.
|
||||
If necessary loads up the database and creates the tables if the
|
||||
database doesn't exist.
|
||||
If necessary loads up the database and creates the tables if the database doesn't exist.
|
||||
"""
|
||||
if AlternativeBookNamesDB.cursor is None:
|
||||
filepath = os.path.join(
|
||||
file_path = os.path.join(
|
||||
AppLocation.get_directory(AppLocation.DataDir), 'bibles', 'alternative_book_names.sqlite')
|
||||
if not os.path.exists(filepath):
|
||||
if not os.path.exists(file_path):
|
||||
#create new DB, create table alternative_book_names
|
||||
AlternativeBookNamesDB.conn = sqlite3.connect(filepath)
|
||||
AlternativeBookNamesDB.conn.execute('CREATE TABLE '
|
||||
'alternative_book_names(id INTEGER NOT NULL, '
|
||||
'book_reference_id INTEGER, language_id INTEGER, name '
|
||||
'VARCHAR(50), PRIMARY KEY (id))')
|
||||
AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
|
||||
AlternativeBookNamesDB.conn.execute(
|
||||
'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, '
|
||||
'book_reference_id INTEGER, language_id INTEGER, name VARCHAR(50), PRIMARY KEY (id))')
|
||||
else:
|
||||
#use existing DB
|
||||
AlternativeBookNamesDB.conn = sqlite3.connect(filepath)
|
||||
AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
|
||||
AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor()
|
||||
return AlternativeBookNamesDB.cursor
|
||||
|
||||
@ -944,14 +884,9 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Run an SQL query on the database, returning the results.
|
||||
|
||||
``query``
|
||||
The actual SQL query to run.
|
||||
|
||||
``parameters``
|
||||
Any variable parameters to add to the query
|
||||
|
||||
``commit``
|
||||
If a commit statement is necessary this should be True.
|
||||
:param query: The actual SQL query to run.
|
||||
:param parameters: Any variable parameters to add to the query
|
||||
:param commit: If a commit statement is necessary this should be True.
|
||||
"""
|
||||
cursor = AlternativeBookNamesDB.get_cursor()
|
||||
cursor.execute(query, parameters)
|
||||
@ -964,19 +899,16 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book_reference_id if the name matches.
|
||||
|
||||
``name``
|
||||
The name to search the id.
|
||||
|
||||
``language_id``
|
||||
The language_id for which language should be searched
|
||||
:param name: The name to search the id.
|
||||
:param language_id: The language_id for which language should be searched
|
||||
"""
|
||||
log.debug('AlternativeBookNamesDB.get_book_reference_id("%s", "%s")', name, language_id)
|
||||
if language_id:
|
||||
books = AlternativeBookNamesDB.run_sql('SELECT book_reference_id, '
|
||||
'name FROM alternative_book_names WHERE language_id = ?', (language_id, ))
|
||||
books = AlternativeBookNamesDB.run_sql(
|
||||
'SELECT book_reference_id, name FROM alternative_book_names WHERE language_id = ?', (language_id, ))
|
||||
else:
|
||||
books = AlternativeBookNamesDB.run_sql('SELECT book_reference_id, '
|
||||
'name FROM alternative_book_names')
|
||||
books = AlternativeBookNamesDB.run_sql(
|
||||
'SELECT book_reference_id, name FROM alternative_book_names')
|
||||
for book in books:
|
||||
if book[1].lower() == name.lower():
|
||||
return book[0]
|
||||
@ -987,19 +919,14 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Add an alternative book name to the database.
|
||||
|
||||
``name``
|
||||
The name of the alternative book name.
|
||||
|
||||
``book_reference_id``
|
||||
The book_reference_id of the book.
|
||||
|
||||
``language_id``
|
||||
The language to which the alternative book name belong.
|
||||
:param name: The name of the alternative book name.
|
||||
:param book_reference_id: The book_reference_id of the book.
|
||||
:param language_id: The language to which the alternative book name belong.
|
||||
"""
|
||||
log.debug('AlternativeBookNamesDB.create_alternative_book_name("%s", '
|
||||
'"%s", "%s"', name, book_reference_id, language_id)
|
||||
return AlternativeBookNamesDB.run_sql('INSERT INTO '
|
||||
'alternative_book_names(book_reference_id, language_id, name) '
|
||||
log.debug('AlternativeBookNamesDB.create_alternative_book_name("%s", "%s", "%s")',
|
||||
name, book_reference_id, language_id)
|
||||
return AlternativeBookNamesDB.run_sql(
|
||||
'INSERT INTO alternative_book_names(book_reference_id, language_id, name) '
|
||||
'VALUES (?, ?, ?)', (book_reference_id, language_id, name), True)
|
||||
|
||||
|
||||
@ -1012,8 +939,7 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def __init__(self, parent, **kwargs):
|
||||
"""
|
||||
The constructor loads up the database and creates and initialises the
|
||||
tables if the database doesn't exist.
|
||||
The constructor loads up the database and creates and initialises the tables if the database doesn't exist.
|
||||
|
||||
**Required keyword arguments:**
|
||||
|
||||
@ -1021,8 +947,7 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
The path to the bible database file.
|
||||
|
||||
``name``
|
||||
The name of the database. This is also used as the file name for
|
||||
SQLite databases.
|
||||
The name of the database. This is also used as the file name for SQLite databases.
|
||||
"""
|
||||
log.info('OldBibleDB loaded')
|
||||
QtCore.QObject.__init__(self)
|
||||
@ -1040,8 +965,8 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
Return the cursor object. Instantiate one if it doesn't exist yet.
|
||||
"""
|
||||
if self.cursor is None:
|
||||
filepath = os.path.join(self.path, self.file)
|
||||
self.connection = sqlite3.connect(filepath)
|
||||
file_path = os.path.join(self.path, self.file)
|
||||
self.connection = sqlite3.connect(file_path)
|
||||
self.cursor = self.connection.cursor()
|
||||
return self.cursor
|
||||
|
||||
@ -1049,11 +974,8 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Run an SQL query on the database, returning the results.
|
||||
|
||||
``query``
|
||||
The actual SQL query to run.
|
||||
|
||||
``parameters``
|
||||
Any variable parameters to add to the query.
|
||||
:param query: The actual SQL query to run.
|
||||
:param parameters: Any variable parameters to add to the query.
|
||||
"""
|
||||
cursor = self.get_cursor()
|
||||
cursor.execute(query, parameters)
|
||||
@ -1092,9 +1014,9 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
if not isinstance(name, str):
|
||||
name = str(name)
|
||||
books = self.run_sql('SELECT id, testament_id, name, '
|
||||
'abbreviation FROM book WHERE LOWER(name) = ? OR '
|
||||
'LOWER(abbreviation) = ?', (name.lower(), name.lower()))
|
||||
books = self.run_sql(
|
||||
'SELECT id, testament_id, name, abbreviation FROM book WHERE LOWER(name) = ? OR '
|
||||
'LOWER(abbreviation) = ?', (name.lower(), name.lower()))
|
||||
if books:
|
||||
return {
|
||||
'id': books[0][0],
|
||||
@ -1122,8 +1044,8 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Returns the verses of the Bible.
|
||||
"""
|
||||
verses = self.run_sql('SELECT book_id, chapter, verse, text FROM '
|
||||
'verse WHERE book_id = ? ORDER BY id', (book_id, ))
|
||||
verses = self.run_sql(
|
||||
'SELECT book_id, chapter, verse, text FROM verse WHERE book_id = ? ORDER BY id', (book_id, ))
|
||||
if verses:
|
||||
return [{
|
||||
'book_id': int(verse[0]),
|
||||
|
Loading…
Reference in New Issue
Block a user