diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index c5dc1da87..da549cd2d 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -40,7 +40,6 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): self.AuthorListView.setColumnHidden(0, True) self.AuthorListView.setColumnWidth(1, 300) self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"])) - self.candelete = False self.currentrow = 0 self.author = None @@ -72,10 +71,9 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): """ Delete the author is the Author is not attached to any songs """ - if self.candelete == True: - self.songmanager.delete_author(self.author.id) - self.on_ClearButton_clicked() - self.load_form() + self.songmanager.delete_author(self.author.id) + self.on_ClearButton_clicked() + self.load_form() @pyqtSignature("") def on_AddUpdateButton_clicked(self): @@ -100,14 +98,15 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): self.DisplayEdit.setText("") self.FirstNameEdit.setText("") self.LastNameEdit.setText("") - self.MessageLabel.setText("") - self.candelete = True + self.MessageLabel.setText("") + self.DeleteButton.setEnabled(True) self.author = None @pyqtSignature("QTableWidgetItem*") def on_AuthorListView_itemClicked(self, item): """ - Slot documentation goes here. + An Author has been selected display it + If the author is attached to a Song prevent delete """ self.currentrow = self.AuthorListView.currentRow() id = int(self.AuthorListView.item(self.currentrow, 0).text()) @@ -119,8 +118,7 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): songs = self.songmanager.get_song_authors_for_author(id) if len(songs) > 0: self.MessageLabel.setText("Author in use 'Delete' is disabled") - self.candelete = False + self.DeleteButton.setEnabled(False) else: self.MessageLabel.setText("Author is not used") - self.candelete = True - + self.DeleteButton.setEnabled(True) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 188c3c16a..4dbdcc2ce 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -27,7 +27,7 @@ from songbookform import SongBookForm from editsongdialog import Ui_EditSongDialog -from openlp.plugins.songs.lib.songtable import Author +from openlp.plugins.songs.lib.songtable import * class EditSongForm(QWidget, Ui_EditSongDialog): """ diff --git a/openlp/plugins/songs/lib/songDBimpl.py b/openlp/plugins/songs/lib/songDBimpl.py index 2f7d4b8c2..7537e0b6b 100644 --- a/openlp/plugins/songs/lib/songDBimpl.py +++ b/openlp/plugins/songs/lib/songDBimpl.py @@ -26,10 +26,11 @@ import string from sqlalchemy import * from sqlalchemy.sql import select from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation, clear_mappers +from sqlalchemy.orm import scoped_session, sessionmaker + +from openlp.plugins.songs.lib.songtables import * +from openlp.plugins.songs.lib.songclasses import * -from openlp.plugins.songs.lib.tables import * -from openlp.plugins.songs.lib.classes import * from openlp.core.utils import ConfigHelper class SongDBException(Exception): @@ -37,17 +38,6 @@ class SongDBException(Exception): class SongInvalidDatabaseError(Exception): pass -clear_mappers() # some reason we need this -mapper(Author, authors_table) -mapper(Book, song_books_table) -mapper(Song, songs_table, - properties={'authors': relation(Author, backref='songs', - secondary=authors_songs_table), - 'book': relation(Book, backref='songs'), - 'topics': relation(Topic, backref='songs', - secondary=songs_topics_table)}) -mapper(Topic, topics_table) - class SongDBImpl(): global log log=logging.getLogger("SongDBImpl") @@ -118,13 +108,14 @@ class SongDBImpl(): def delete_author(self, authorid): log.debug( "delete_author %s" , authorid) -# metadata.bind.echo = True + metadata.bind.echo = True # s = text (""" delete FROM authors where authorid = :i """) # return self.db.execute(s, i=authorid) session = self.Session() author = session.query(Author).get(authorid) session.delete(author) session.commit() + def update_author(self, authorid, author_name, first_name, last_name): log.debug( "update_author %s,%s,%s,%s" , authorid, author_name, first_name, last_name) diff --git a/openlp/plugins/songs/lib/classes.py b/openlp/plugins/songs/lib/songclasses.py similarity index 73% rename from openlp/plugins/songs/lib/classes.py rename to openlp/plugins/songs/lib/songclasses.py index a693641d3..eedcdd625 100644 --- a/openlp/plugins/songs/lib/classes.py +++ b/openlp/plugins/songs/lib/songclasses.py @@ -16,6 +16,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ +from sqlalchemy.orm import mapper, relation +from openlp.plugins.songs.lib.tables import * class BaseModel(object): """ @@ -56,3 +58,14 @@ class Topic(BaseModel): Topic model """ pass + + +mapper(Author, authors_table) +mapper(Book, song_books_table) +mapper(Song, songs_table, + properties={'authors': relation(Author, backref='songs', + secondary=authors_songs_table), + 'book': relation(Book, backref='songs'), + 'topics': relation(Topic, backref='songs', + secondary=songs_topics_table)}) +mapper(Topic, topics_table) diff --git a/openlp/plugins/songs/lib/songtable.py b/openlp/plugins/songs/lib/songtable.py deleted file mode 100644 index 7deef3d94..000000000 --- a/openlp/plugins/songs/lib/songtable.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -OpenLP - Open Source Lyrics Projection -Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -""" -class Author(object): - def __init__(self, authorname, first_name, last_name): - self.authorname =authorname - self.first_name =first_name - self.last_name =last_name - - def __repr__(self): - return "" %(self.authorname, self.first_name, self.last_name) - - def get_author(self): - return self.authorname, self.first_name, self.last_name - - def get_author_name(self): - return self.authorname diff --git a/openlp/plugins/songs/lib/tables.py b/openlp/plugins/songs/lib/songtables.py similarity index 98% rename from openlp/plugins/songs/lib/tables.py rename to openlp/plugins/songs/lib/songtables.py index a5df053f6..42889d8be 100644 --- a/openlp/plugins/songs/lib/tables.py +++ b/openlp/plugins/songs/lib/songtables.py @@ -14,7 +14,7 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +Place, Suite 330, Boston, MA 02111-1307 USA """ from sqlalchemy import Column, Table, MetaData, ForeignKey, types diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 331f5bd4b..7f9f19c73 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -26,7 +26,7 @@ from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem from forms import EditSongForm, OpenLPImportForm, OpenSongImportForm, \ OpenLPExportForm, OpenSongExportForm from openlp.plugins.songs.lib import SongManager -from openlp.plugins.songs.lib.classes import * +from openlp.plugins.songs.lib.songclasses import * class SongsPlugin(Plugin, PluginUtils): global log