openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #02421
[Merge] lp:~googol-hush/openlp/trivial into lp:openlp
googol has proposed merging lp:~googol-hush/openlp/trivial into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Added redundancy control for Books, Authors and Topics. Now, you cannot add a Book, Author or Topic which is already in the list. Furthermore you cannot submit an edited Book, Author or Topic which is already in the list (e. g. editing the Topic "Penetcost" to "Pentecost" will not work when a topic "Pentecost" already exists).
--
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/29636
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/trivial into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/songmaintenanceform.py'
--- openlp/plugins/songs/forms/songmaintenanceform.py 2010-06-28 13:38:29 +0000
+++ openlp/plugins/songs/forms/songmaintenanceform.py 2010-07-10 18:24:44 +0000
@@ -97,6 +97,9 @@
QtGui.QMessageBox.critical(self, dlg_title, sel_text)
def resetAuthors(self):
+ """
+ Reloads the Authors list.
+ """
self.AuthorsListWidget.clear()
authors = self.songmanager.get_all_objects(Author, Author.display_name)
for author in authors:
@@ -109,6 +112,9 @@
self.AuthorsListWidget.addItem(author_name)
def resetTopics(self):
+ """
+ Reloads the Topics list.
+ """
self.TopicsListWidget.clear()
topics = self.songmanager.get_all_objects(Topic, Topic.name)
for topic in topics:
@@ -117,13 +123,89 @@
self.TopicsListWidget.addItem(topic_name)
def resetBooks(self):
+ """
+ Reloads the Books list.
+ """
self.BooksListWidget.clear()
books = self.songmanager.get_all_objects(Book, Book.name)
for book in books:
- book_name = QtGui.QListWidgetItem(book.name)
+ book_name = QtGui.QListWidgetItem(u'%s (%s)' % (book.name,
+ book.publisher))
book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id))
self.BooksListWidget.addItem(book_name)
+ def checkAuthor(self, new_author, edit=False):
+ """
+ Returns True when the given Author is already in the list elsewise False.
+ """
+ new_author_first_name = new_author.first_name
+ new_author_last_name = new_author.last_name
+ new_author_display_name = new_author.display_name
+ authors = self.songmanager.get_all_objects(Author)
+ author_exists = False
+ for author in authors:
+ author_fist_name = author.first_name
+ author_last_name = author.last_name
+ author_display_name = author.display_name
+ if author_fist_name == new_author_first_name and \
+ author_last_name == new_author_last_name and \
+ author_display_name == new_author_display_name:
+ author_exists = True
+ #If we edit an exsisting Author, we need to make sure that we do
+ #not return True when nothing has changed (because this would
+ #cause an error message later on)
+ if edit:
+ new_author_id = new_author.id
+ author_id = author.id
+ if new_author_id == author_id:
+ author_exists = False
+ return author_exists
+
+ def checkTopic(self, new_topic, edit=False):
+ """
+ Returns True when the given Topic is already in the list elsewise False.
+ """
+ new_topic_name = new_topic.name
+ topics = self.songmanager.get_all_objects(Topic)
+ topic_exists = False
+ for topic in topics:
+ topic_name = topic.name
+ if topic_name == new_topic_name:
+ topic_exists = True
+ #If we edit an exsisting Topic, we need to make sure that we do
+ #not return True when nothing has changed (because this would
+ #cause an error message later on)
+ if edit:
+ new_topic_id = new_topic.id
+ topic_id = topic.id
+ if new_topic_id == topic_id:
+ topic_exists = False
+ return topic_exists
+
+ def checkBook(self, new_book, edit=False):
+ """
+ Returns True when the given Book is already in the list elsewise False.
+ """
+ new_book_name = new_book.name
+ new_book_publisher = new_book.publisher
+ books = self.songmanager.get_all_objects(Book)
+ book_exists = False
+ for book in books:
+ book_name = book.name
+ book_publisher = book.publisher
+ if book_publisher == new_book_publisher and \
+ book_name == new_book_name:
+ book_exists = True
+ #If we edit an exsisting Book, we need to make sure that we do
+ #not return True when nothing has changed (because this would
+ #cause an error message later on)
+ if edit:
+ new_book_id = new_book.id
+ book_id = book.id
+ if new_book_id == book_id:
+ book_exists = False
+ return book_exists
+
def onAuthorAddButtonClick(self):
self.authorform.setAutoDisplayName(True)
if self.authorform.exec_():
@@ -131,40 +213,40 @@
first_name=unicode(self.authorform.FirstNameEdit.text()),
last_name=unicode(self.authorform.LastNameEdit.text()),
display_name=unicode(self.authorform.DisplayEdit.text()))
- if self.songmanager.save_object(author):
+ if self.checkAuthor(author) is False and \
+ self.songmanager.save_object(author):
self.resetAuthors()
else:
- QtGui.QMessageBox.critical(
- self, translate('SongsPlugin.SongMaintenanceForm',
- 'Error'),
+ QtGui.QMessageBox.critical(self,
+ translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Couldn\'t add your author.'))
+ 'Could not add your author.'))
def onTopicAddButtonClick(self):
if self.topicform.exec_():
topic = Topic.populate(name=unicode(self.topicform.NameEdit.text()))
- if self.songmanager.save_object(topic):
+ if self.checkTopic(topic) is False and \
+ self.songmanager.save_object(topic):
self.resetTopics()
else:
- QtGui.QMessageBox.critical(
- self, translate('SongsPlugin.SongMaintenanceForm',
- 'Error'),
+ QtGui.QMessageBox.critical(self,
+ translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Couldn\'t add your topic.'))
+ 'Could not add your topic.'))
def onBookAddButtonClick(self):
if self.bookform.exec_():
book = Book.populate(
name=unicode(self.bookform.NameEdit.text()),
publisher=unicode(self.bookform.PublisherEdit.text()))
- if self.songmanager.save_object(book):
+ if self.checkBook(book) is False and \
+ self.songmanager.save_object(book):
self.resetBooks()
else:
- QtGui.QMessageBox.critical(
- self, translate('SongsPlugin.SongMaintenanceForm',
- 'Error'),
+ QtGui.QMessageBox.critical(self,
+ translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Couldn\'t add your book.'))
+ 'Could not add your book.'))
def onAuthorEditButtonClick(self):
author_id = self._getCurrentItemId(self.AuthorsListWidget)
@@ -187,14 +269,14 @@
author.last_name = unicode(self.authorform.LastNameEdit.text())
author.display_name = unicode(
self.authorform.DisplayEdit.text())
- if self.songmanager.save_object(author):
+ if self.checkAuthor(author, True) is False and \
+ self.songmanager.save_object(author):
self.resetAuthors()
else:
- QtGui.QMessageBox.critical(
- self, translate('SongsPlugin.SongMaintenanceForm',
- 'Error'),
+ QtGui.QMessageBox.critical(self,
+ translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Couldn\'t save your author.'))
+ 'Could not save your author.'))
def onTopicEditButtonClick(self):
topic_id = self._getCurrentItemId(self.TopicsListWidget)
@@ -203,14 +285,14 @@
self.topicform.NameEdit.setText(topic.name)
if self.topicform.exec_(False):
topic.name = unicode(self.topicform.NameEdit.text())
- if self.songmanager.save_object(topic):
+ if self.checkTopic(topic, True) is False and \
+ self.songmanager.save_object(topic):
self.resetTopics()
else:
- QtGui.QMessageBox.critical(
- self, translate('SongsPlugin.SongMaintenanceForm',
- 'Error'),
+ QtGui.QMessageBox.critical(self,
+ translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Couldn\'t save your topic.'))
+ 'Could not save your topic.'))
def onBookEditButtonClick(self):
book_id = self._getCurrentItemId(self.BooksListWidget)
@@ -221,14 +303,14 @@
if self.bookform.exec_(False):
book.name = unicode(self.bookform.NameEdit.text())
book.publisher = unicode(self.bookform.PublisherEdit.text())
- if self.songmanager.save_object(book):
+ if self.checkBook(book, True) is False and \
+ self.songmanager.save_object(book):
self.resetBooks()
else:
- QtGui.QMessageBox.critical(
- self, translate('SongsPlugin.SongMaintenanceForm',
- 'Error'),
+ QtGui.QMessageBox.critical(self,
+ translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Couldn\'t save your book.'))
+ 'Could not save your book.'))
def onAuthorDeleteButtonClick(self):
"""
@@ -236,13 +318,12 @@
"""
self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors,
translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'Are you sure you want to delete the selected author?'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'This author can\'t be deleted, they are currently '
- 'assigned to at least one song.'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'No author selected!'))
+ translate('SongsPlugin.SongMaintenanceForm',
+ 'Are you sure you want to delete the selected author?'),
+ translate('SongsPlugin.SongMaintenanceForm',
+ 'This author ca not be deleted, they are currently '
+ 'assigned to at least one song.'),
+ translate('SongsPlugin.SongMaintenanceForm', 'No author selected!'))
def onTopicDeleteButtonClick(self):
"""
@@ -250,13 +331,12 @@
"""
self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics,
translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'Are you sure you want to delete the selected topic?'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'This topic can\'t be deleted, it is currently '
- 'assigned to at least one song.'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'No topic selected!'))
+ translate('SongsPlugin.SongMaintenanceForm',
+ 'Are you sure you want to delete the selected topic?'),
+ translate('SongsPlugin.SongMaintenanceForm',
+ 'This topic cannot be deleted, it is currently '
+ 'assigned to at least one song.'),
+ translate('SongsPlugin.SongMaintenanceForm', 'No topic selected!'))
def onBookDeleteButtonClick(self):
"""
@@ -265,8 +345,8 @@
self._deleteItem(Book, self.BooksListWidget, self.resetBooks,
translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),
translate('SongsPlugin.SongMaintenanceForm',
- 'Are you sure you want to delete the selected book?'),
- translate('SongsPlugin.SongMaintenanceForm',
- 'This book can\'t be deleted, it is currently '
- 'assigned to at least one song.'),
- translate('SongsPlugin.SongMaintenanceForm', u'No book selected!'))
+ 'Are you sure you want to delete the selected book?'),
+ translate('SongsPlugin.SongMaintenanceForm',
+ 'This book cannot be deleted, it is currently '
+ 'assigned to at least one song.'),
+ translate('SongsPlugin.SongMaintenanceForm', 'No book selected!'))
Follow ups