updated bibles_resources.sqlite with some additional apocryph books

comparing books with lower()
display only which are not added to a bible in BookNameForm
small fixes
This commit is contained in:
Armin Köhler 2011-05-02 15:45:30 +02:00
parent 5b93b821b8
commit 3eca8f6b50
4 changed files with 57 additions and 29 deletions

View File

@ -27,7 +27,7 @@
The bible import functions for OpenLP The bible import functions for OpenLP
""" """
import logging import logging
import os #import os
import os.path import os.path
import re import re
@ -637,6 +637,11 @@ class BibleUpgradeForm(OpenLPWizard):
db_book = self.newbibles[number].create_book(book[u'name'], db_book = self.newbibles[number].create_book(book[u'name'],
book_ref_id, book_details[u'testament_id']) book_ref_id, book_details[u'testament_id'])
verses = oldbible.get_verses(book[u'id']) verses = oldbible.get_verses(book[u'id'])
if not verses:
log.exception(u'No verses found to import for book '
u'"%s"', book[u'name'])
self.newbibles[number].delete_book(db_book)
continue
for verse in verses: for verse in verses:
self.newbibles[number].create_verse(db_book.id, self.newbibles[number].create_verse(db_book.id,
int(verse[u'chapter']), int(verse[u'chapter']),

View File

@ -53,12 +53,18 @@ class BookNameForm(QDialog, Ui_BookNameDialog):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
def exec_(self, name): def exec_(self, name, books):
items = [] items = []
self.requestComboBox.addItem(u'') self.requestComboBox.addItem(u'')
self.requestLabel.setText(name) self.requestLabel.setText(name)
items = BiblesResourcesDB.get_books() items = BiblesResourcesDB.get_books()
for item in items: for item in items:
addBook = True
for book in books:
if book.book_reference_id == item[u'id']:
addBook = False
break
if addBook == True:
self.requestComboBox.addItem(item[u'name']) self.requestComboBox.addItem(item[u'name'])
return QDialog.exec_(self) return QDialog.exec_(self)

View File

@ -218,6 +218,18 @@ class BibleDB(QtCore.QObject, Manager):
self.save_object(book) self.save_object(book)
return book return book
def delete_book(self, db_book):
"""
Delete a book from the database.
``db_book``
The book objekt.
"""
log.debug(u'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, textlist):
""" """
Add a chapter and its verses to a book. Add a chapter and its verses to a book.
@ -318,8 +330,8 @@ class BibleDB(QtCore.QObject, Manager):
def get_book_ref_id_by_name(self, book, language_id=None): def get_book_ref_id_by_name(self, book, language_id=None):
log.debug(u'BibleDB.get_book_ref_id_by_name:("%s", "%s")', book, log.debug(u'BibleDB.get_book_ref_id_by_name:("%s", "%s")', book,
language_id) language_id)
if BiblesResourcesDB.get_book(book): if BiblesResourcesDB.get_book(book, True):
book_temp = BiblesResourcesDB.get_book(book) book_temp = BiblesResourcesDB.get_book(book, True)
book_id = book_temp[u'id'] book_id = book_temp[u'id']
elif BiblesResourcesDB.get_alternative_book_name(book, language_id): elif BiblesResourcesDB.get_alternative_book_name(book, language_id):
book_id = BiblesResourcesDB.get_alternative_book_name(book, book_id = BiblesResourcesDB.get_alternative_book_name(book,
@ -332,7 +344,7 @@ class BibleDB(QtCore.QObject, Manager):
from openlp.plugins.bibles.forms import BookNameForm from openlp.plugins.bibles.forms import BookNameForm
book_ref = None book_ref = None
book_name = BookNameForm(self.wizard) book_name = BookNameForm(self.wizard)
if book_name.exec_(book): if book_name.exec_(book, self.get_books()):
book_ref = unicode(book_name.requestComboBox.currentText()) book_ref = unicode(book_name.requestComboBox.currentText())
if not book_ref: if not book_ref:
return None return None
@ -551,7 +563,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
] ]
@staticmethod @staticmethod
def get_book(name): def get_book(name, lower=False):
""" """
Return a book by name or abbreviation. Return a book by name or abbreviation.
@ -561,9 +573,15 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
log.debug(u'BiblesResourcesDB.get_book("%s")', name) log.debug(u'BiblesResourcesDB.get_book("%s")', name)
if not isinstance(name, unicode): if not isinstance(name, unicode):
name = unicode(name) name = unicode(name)
if lower:
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM book_reference WHERE name = ? OR ' u'abbreviation, chapters FROM book_reference WHERE '
u'abbreviation = ?', (name, name)) u'LOWER(name) = ? OR LOWER(abbreviation) = ?',
(name.lower(), name.lower()))
else:
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM book_reference WHERE name = ?'
u' OR abbreviation = ?', (name, name))
if books: if books:
return { return {
u'id': books[0][0], u'id': books[0][0],
@ -758,16 +776,15 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
log.debug(u'BiblesResourcesDB.get_alternative_book_name("%s", "%s")', log.debug(u'BiblesResourcesDB.get_alternative_book_name("%s", "%s")',
name, language_id) name, language_id)
if language_id: if language_id:
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id ' books = BiblesResourcesDB.run_sql(u'SELECT book_reference_id, name '
u'FROM alternative_book_names WHERE name = ? and language_id ' u'FROM alternative_book_names WHERE language_id = ? ORDER BY '
u'= ? ORDER BY id', (name, language_id)) u'id', (language_id, ))
else:
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id '
u'FROM alternative_book_names WHERE name = ? ORDER BY id',
(name, ))
if id:
return int(id[0][0])
else: else:
books = BiblesResourcesDB.run_sql(u'SELECT book_reference_id, name '
u'FROM alternative_book_names ORDER BY id')
for book in books:
if book[1].lower() == name.lower():
return book[0]
return None return None
@staticmethod @staticmethod
@ -899,16 +916,16 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
log.debug(u'AlternativeBookNamesDB.get_book_reference_id("%s", "%s")', log.debug(u'AlternativeBookNamesDB.get_book_reference_id("%s", "%s")',
name, language_id) name, language_id)
if language_id: if language_id:
id = AlternativeBookNamesDB.run_sql(u'SELECT book_reference_id FROM' books = AlternativeBookNamesDB.run_sql(u'SELECT book_reference_id, '
u' alternative_book_names WHERE name = ? AND language_id = ?', u'name FROM alternative_book_names WHERE language_id = ?',
(name, language_id)) (language_id, ))
else: else:
id = AlternativeBookNamesDB.run_sql(u'SELECT book_reference_id FROM' books = AlternativeBookNamesDB.run_sql(u'SELECT book_reference_id, '
u' alternative_book_names WHERE name = ?', name) u'name FROM alternative_book_names')
if not id: for book in books:
if book[1].lower() == name.lower():
return book[0]
return None return None
else:
return id[0][0]
@staticmethod @staticmethod
def create_alternative_book_name(name, book_reference_id, language_id): def create_alternative_book_name(name, book_reference_id, language_id):