Clean up files and correct mapper issues

Update Author Delete UI State

bzr-revno: 282
This commit is contained in:
Tim Bentley 2009-01-11 08:51:43 +00:00
parent 29c4379275
commit cc0ca326c3
7 changed files with 31 additions and 60 deletions

View File

@ -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)

View File

@ -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):
"""

View File

@ -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)

View File

@ -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)

View File

@ -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 "<authormeta(%r,%r,%r)>" %(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

View File

@ -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

View File

@ -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