From d4eac0693520ae8a98e810d3f3a51256b7f9746c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Fri, 20 Apr 2012 21:14:23 +0200 Subject: [PATCH] refer localized booknames to the corresponding english one --- openlp/plugins/bibles/forms/booknamedialog.py | 2 +- openlp/plugins/bibles/forms/booknameform.py | 11 +++++++++++ openlp/plugins/bibles/lib/db.py | 18 +++--------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/openlp/plugins/bibles/forms/booknamedialog.py b/openlp/plugins/bibles/forms/booknamedialog.py index db056cce3..b0ab9ade1 100644 --- a/openlp/plugins/bibles/forms/booknamedialog.py +++ b/openlp/plugins/bibles/forms/booknamedialog.py @@ -90,7 +90,7 @@ class Ui_BookNameDialog(object): 'Select Book Name')) self.infoLabel.setText(translate('BiblesPlugin.BookNameDialog', 'The following book name cannot be matched up internally. Please ' - 'select the corresponding English name from the list.')) + 'select the corresponding name from the list.')) self.currentLabel.setText(translate('BiblesPlugin.BookNameDialog', 'Current name:')) self.correspondingLabel.setText(translate( diff --git a/openlp/plugins/bibles/forms/booknameform.py b/openlp/plugins/bibles/forms/booknameform.py index 2f783d070..b3325c853 100644 --- a/openlp/plugins/bibles/forms/booknameform.py +++ b/openlp/plugins/bibles/forms/booknameform.py @@ -28,6 +28,7 @@ Module implementing BookNameForm. """ import logging +import re from PyQt4.QtGui import QDialog from PyQt4 import QtCore @@ -56,6 +57,7 @@ class BookNameForm(QDialog, Ui_BookNameDialog): self.setupUi(self) self.customSignals() self.booknames = BibleStrings().Booknames + self.book_id = False def customSignals(self): """ @@ -123,4 +125,13 @@ class BookNameForm(QDialog, Ui_BookNameDialog): self.correspondingComboBox.setFocus() return False else: + cor_book = unicode(self.correspondingComboBox.currentText()) + for character in u'\\.^$*+?{}[]()': + cor_book = cor_book.replace(character, u'\\' + character) + books = filter(lambda key: + re.match(cor_book, unicode(self.booknames[key]), re.UNICODE), + self.booknames.keys()) + books = filter(None, map(BiblesResourcesDB.get_book, books)) + if books: + self.book_id = books[0][u'id'] return QDialog.accept(self) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 15f4147e3..6595103f6 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -332,6 +332,7 @@ class BibleDB(QtCore.QObject, Manager): def get_book_ref_id_by_name(self, book, maxbooks, language_id=None): log.debug(u'BibleDB.get_book_ref_id_by_name:("%s", "%s")', book, language_id) + book_id = None if BiblesResourcesDB.get_book(book, True): book_temp = BiblesResourcesDB.get_book(book, True) book_id = book_temp[u'id'] @@ -341,26 +342,13 @@ class BibleDB(QtCore.QObject, Manager): book_id = AlternativeBookNamesDB.get_book_reference_id(book) else: from openlp.plugins.bibles.forms import BookNameForm - book_ref = None book_name = BookNameForm(self.wizard) if book_name.exec_(book, self.get_books(), maxbooks): - book_ref = unicode( - book_name.correspondingComboBox.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 + book_id = book_name.book_id if book_id: AlternativeBookNamesDB.create_alternative_book_name( book, book_id, language_id) - if book_id: - return book_id - else: - return None + return book_id def get_verses(self, reference_list, show_error=True): """