openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #02424
[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/29642
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 21:47:41 +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,71 @@
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.
+ """
+ authors = self.songmanager.get_all_objects(Author)
+ author_exists = False
+ for author in authors:
+ 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 existing 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:
+ 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.
+ """
+ topics = self.songmanager.get_all_objects(Topic)
+ topic_exists = False
+ for topic in topics:
+ if topic.name == new_topic.name:
+ topic_exists = True
+ #If we edit an existing 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:
+ 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.
+ """
+ books = self.songmanager.get_all_objects(Book)
+ book_exists = False
+ for book in books:
+ if book.publisher == new_book.publisher and \
+ book.name == new_book.name:
+ book_exists = True
+ #If we edit an existing 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:
+ 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 +195,39 @@
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 not self.checkAuthor(author) 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 not self.checkTopic(topic) 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 not self.checkBook(book) 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 +250,14 @@
author.last_name = unicode(self.authorform.LastNameEdit.text())
author.display_name = unicode(
self.authorform.DisplayEdit.text())
- if self.songmanager.save_object(author):
+ if not self.checkAuthor(author, True) 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 +266,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 not self.checkTopic(topic, True) 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 +284,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 not self.checkBook(book, True) 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 +299,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 cannot be deleted, they are currently '
+ 'assigned to at least one song.'),
+ translate('SongsPlugin.SongMaintenanceForm', 'No author selected!'))
def onTopicDeleteButtonClick(self):
"""
@@ -250,13 +312,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 +326,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