Fix topic/author adding (Bug #607034)

bzr-revno: 955
This commit is contained in:
Jon Tibble 2010-07-20 18:03:04 +01:00
commit ee4802735d
2 changed files with 8 additions and 4 deletions

View File

@ -135,16 +135,20 @@ class Manager(object):
settings.endGroup() settings.endGroup()
self.session = init_schema(self.db_url) self.session = init_schema(self.db_url)
def save_object(self, object_instance): def save_object(self, object_instance, commit=True):
""" """
Save an object to the database Save an object to the database
``object_instance`` ``object_instance``
The object to save The object to save
``commit``
Commit the session with this object
""" """
try: try:
self.session.add(object_instance) self.session.add(object_instance)
self.session.commit() if commit:
self.session.commit()
return True return True
except InvalidRequestError: except InvalidRequestError:
self.session.rollback() self.session.rollback()

View File

@ -290,7 +290,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
author = Author.populate(first_name=text.rsplit(u' ', 1)[0], author = Author.populate(first_name=text.rsplit(u' ', 1)[0],
last_name=text.rsplit(u' ', 1)[1], display_name=text) last_name=text.rsplit(u' ', 1)[1], display_name=text)
self.songmanager.save_object(author) self.songmanager.save_object(author, False)
self.song.authors.append(author) self.song.authors.append(author)
author_item = QtGui.QListWidgetItem( author_item = QtGui.QListWidgetItem(
unicode(author.display_name)) unicode(author.display_name))
@ -350,7 +350,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
topic = Topic.populate(name=text) topic = Topic.populate(name=text)
self.songmanager.save_object(topic) self.songmanager.save_object(topic, False)
self.song.topics.append(topic) self.song.topics.append(topic)
topic_item = QtGui.QListWidgetItem(unicode(topic.name)) topic_item = QtGui.QListWidgetItem(unicode(topic.name))
topic_item.setData(QtCore.Qt.UserRole, topic_item.setData(QtCore.Qt.UserRole,