some fixes - improve error handling with duplicate book names

This commit is contained in:
Armin Köhler 2012-04-03 20:42:21 +02:00
parent 770fe855ee
commit 800510f2f8
4 changed files with 56 additions and 27 deletions

View File

@ -28,7 +28,7 @@
from PyQt4 import QtCore, QtGui
from openlp.core.lib import build_icon, translate
from openlp.core.lib.ui import UiStrings, create_accept_reject_button_box
from openlp.core.lib.ui import create_accept_reject_button_box
from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
@ -36,7 +36,7 @@ from openlp.plugins.bibles.lib.db import BiblesResourcesDB
class Ui_EditBibleDialog(object):
def setupUi(self, editBibleDialog):
editBibleDialog.setObjectName(u'editBibleDialog')
editBibleDialog.resize(650, 400)
editBibleDialog.resize(600, 400)
editBibleDialog.setWindowIcon(
build_icon(u':/icon/openlp-logo-16x16.png'))
editBibleDialog.setModal(True)
@ -166,11 +166,11 @@ class Ui_EditBibleDialog(object):
self.languageSelectionComboBox.setItemText(LanguageSelection.English+1,
translate('BiblesPlugin.EditBibleForm', 'English'))
self.languageSelectionComboBox.setToolTip(
translate('BiblesPlugin.EditBibleForm', 'Multiple options:\n '
translate('BiblesPlugin.EditBibleForm', 'Multiple options:\n'
'General Settings - the option choosen in settings section\n'
'Bible language - the language in which the Bible book names '
'were imported\n Application language - the language you have '
'chosen for OpenLP\n English - always use English book names'))
'were imported\nApplication language - the language you have '
'chosen for OpenLP\nEnglish - always use English book names'))
for book in BiblesResourcesDB.get_books():
self.bookNameLabel[book[u'abbreviation']].setText(
u'%s:' % unicode(self.booknames[book[u'abbreviation']]))

View File

@ -26,16 +26,15 @@
###############################################################################
import logging
import re
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, \
create_separated_list
from openlp.core.lib import Receiver, translate
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.core.utils import AppLocation
from editbibledialog import Ui_EditBibleDialog
from openlp.plugins.bibles.lib import BibleStrings
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, BiblesResourcesDB
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)
@ -89,9 +88,8 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
self.scrollArea.setParent(None)
else:
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
'You could customize the Book Names of this Bible.\nTo use '
'the Book Names below, you have to choose the option "Bible '
'language" in general settings or explicit for this Bible.'))
'To use the customized Book Names, choose the option "Bible '
'language"\nin general settings or explicit for this Bible.'))
for book in BiblesResourcesDB.get_books():
self.books[book[u'abbreviation']] = self.manager.get_book_by_id(
self.bible, book[u'id'])
@ -125,12 +123,12 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
self.permissions = unicode(self.permissionsEdit.text())
self.bookname_language = \
self.languageSelectionComboBox.currentIndex()-1
for error in self.validate_error:
self.changeBackgroundColor(error, 'white')
if not self.validateMeta():
save = False
if not self.webbible and save:
custom_names = {}
for error in self.validate_error:
self.changeBackgroundColor(error, 'white')
for abbr, book in self.books.iteritems():
if book:
custom_names[abbr] = unicode(self.bookNameEdit[abbr].text())
@ -139,6 +137,8 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
save = False
break
if save:
Receiver.send_message(u'openlp_process_events')
Receiver.send_message(u'cursor_busy')
self.manager.save_meta_data(self.bible, self.version,
self.copyright, self.permissions, self.bookname_language)
if not self.webbible:
@ -148,6 +148,7 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
book.name = custom_names[abbr]
self.manager.update_book(self.bible, book)
self.bible = None
Receiver.send_message(u'cursor_normal')
QtGui.QDialog.accept(self)
def validateMeta(self):
@ -155,27 +156,33 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
Validate the Meta before saving.
"""
if not self.version:
self.changeBackgroundColor(self.versionNameEdit, 'red')
self.validate_error = [self.versionNameEdit]
self.versionNameEdit.setFocus()
critical_error_message_box(UiStrings().EmptyField,
translate('BiblesPlugin.BibleEditForm',
'You need to specify a version name for your Bible.'))
self.versionNameEdit.setFocus()
return False
elif not self.copyright:
self.changeBackgroundColor(self.copyrightEdit, 'red')
self.validate_error = [self.copyrightEdit]
self.copyrightEdit.setFocus()
critical_error_message_box(UiStrings().EmptyField,
translate('BiblesPlugin.BibleEditForm',
'You need to set a copyright for your Bible. '
'Bibles in the Public Domain need to be marked as such.'))
self.copyrightEdit.setFocus()
return False
elif self.manager.exists(self.version) and \
self.manager.get_meta_data(self.bible, u'Version').value != \
self.version:
self.changeBackgroundColor(self.versionNameEdit, 'red')
self.validate_error = [self.versionNameEdit]
self.versionNameEdit.setFocus()
critical_error_message_box(
translate('BiblesPlugin.BibleEditForm', 'Bible Exists'),
translate('BiblesPlugin.BibleEditForm',
'This Bible already exists. Please import '
'a different Bible or first delete the existing one.'))
self.versionNameEdit.setFocus()
return False
return True
@ -183,6 +190,7 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
"""
Validate a book.
"""
book_regex = re.compile(u'[\d]*[^\d]+$')
if not new_bookname:
self.changeBackgroundColor(self.bookNameEdit[abbreviation], 'red')
self.validate_error = [self.bookNameEdit[abbreviation]]
@ -192,9 +200,21 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
'You need to specify a book name for "%s".')) %
self.booknames[abbreviation])
return False
elif not book_regex.match(new_bookname):
self.changeBackgroundColor(self.bookNameEdit[abbreviation], 'red')
self.validate_error = [self.bookNameEdit[abbreviation]]
self.bookNameEdit[abbreviation].setFocus()
critical_error_message_box(UiStrings().EmptyField,
unicode(translate('BiblesPlugin.BibleEditForm',
'The book name "%s" is not correct.\nDecimal digits only could '
'be used at the beginning and\nmust be followed by one or more '
'non-digit characters')) % new_bookname)
return False
for abbr, book in self.books.iteritems():
if book:
if book.name == new_bookname:
if abbr == abbreviation:
continue
if unicode(self.bookNameEdit[abbr].text()) == new_bookname:
self.changeBackgroundColor(self.bookNameEdit[abbreviation],
'red')
self.bookNameEdit[abbreviation].setFocus()

View File

@ -327,9 +327,13 @@ class BibleManager(object):
'Import Wizard to install one or more Bibles.')
})
return None
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
language_selection = self.get_meta_data(bible, u'Bookname language')
if language_selection:
language_selection = int(language_selection.value)
if language_selection == None or language_selection == -1:
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
reflist = parse_reference(versetext, self.db_cache[bible],
language_selection, book_ref_id)
if reflist:
@ -415,7 +419,7 @@ class BibleManager(object):
return None
def save_meta_data(self, bible, version, copyright, permissions,
bookname_language):
bookname_language=-1):
"""
Saves the bibles meta data.
"""

View File

@ -433,7 +433,7 @@ class BibleMediaItem(MediaManagerItem):
bible, u'Bookname language')
if language_selection:
language_selection = int(language_selection.value)
if not language_selection or language_selection == -1:
if language_selection == None or language_selection == -1:
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
@ -508,9 +508,14 @@ class BibleMediaItem(MediaManagerItem):
secondbook.book_reference_id:
book_data_temp.append(book)
book_data = book_data_temp
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
language_selection = self.plugin.manager.get_meta_data(
bible, u'Bookname language')
if language_selection:
language_selection = int(language_selection.value)
if language_selection == None or language_selection == -1:
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
if language_selection == LanguageSelection.Bible:
books = [book.name + u' ' for book in book_data]
elif language_selection == LanguageSelection.Application: