Couple of changes to the Songs plugin classes - trying to get SQLAlchemy to work.

bzr-revno: 292
This commit is contained in:
Raoul Snyman 2009-02-01 21:12:18 +00:00
parent bd510467d5
commit 6ea70e92a1
10 changed files with 96 additions and 109 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
<!-- eric4 user project file for project openlp.org 2.0 -->
<!-- Saved: 2009-01-17, 13:06:08 -->
<!-- Saved: 2009-01-27, 23:44:25 -->
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
<UserProject version="4.0">
</UserProject>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
<!-- eric4 tasks file for project openlp.org 2.0 -->
<!-- Saved: 2009-01-17, 13:06:08 -->
<!-- Saved: 2009-01-27, 23:44:25 -->
<Tasks version="4.2">
<Task priority="1" completed="False" bugfix="False">
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-4.4.dtd">
<!-- eric4 project file for project openlp.org 2.0 -->
<!-- Saved: 2009-01-17, 13:05:58 -->
<!-- Saved: 2009-01-27, 23:44:25 -->
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
<Project version="4.4">
<ProgLanguage mixed="0">Python</ProgLanguage>
@ -66,7 +66,6 @@
<Source>openlp/plugins/bibles/bibleplugin.py</Source>
<Source>openlp/plugins/bibles/forms/bibleimportdialog.py</Source>
<Source>openlp/plugins/bibles/forms/bibleimportform.py</Source>
<Source>openlp/plugins/bibles/lib/biblemanager.py</Source>
<Source>openlp/plugins/bibles/lib/bibleDBimpl.py</Source>
<Source>openlp/plugins/bibles/lib/bibleOSISimpl.py</Source>
<Source>openlp/plugins/bibles/lib/bibleHTTPimpl.py</Source>
@ -74,7 +73,6 @@
<Source>openlp/plugins/bibles/__init__.py</Source>
<Source>openlp/plugins/bibles/lib/__init__.py</Source>
<Source>openlp/plugins/bibles/forms/__init__.py</Source>
<Source>openlp/plugins/bibles/lib/biblecommon.py</Source>
<Source>openlp/plugins/songs/lib/__init__.py</Source>
<Source>openlp/plugins/songs/lib/songxml.py</Source>
<Source>openlp/plugins/songs/lib/models.py</Source>
@ -93,12 +91,8 @@
<Source>openlp/plugins/videos/videoplugin.py</Source>
<Source>openlp/plugins/images/__init__.py</Source>
<Source>openlp/plugins/images/imageplugin.py</Source>
<Source>openlp/plugins/songs/lib/songinterface.py</Source>
<Source>openlp/plugins/songs/lib/songfile.py</Source>
<Source>openlp/plugins/songs/forms/editsongdialog.py</Source>
<Source>openlp/core/lib/pluginutils.py</Source>
<Source>openlp/plugins/songs/lib/songmanager.py</Source>
<Source>openlp/plugins/songs/lib/songDBimpl.py</Source>
<Source>openlpcnv.pyw</Source>
<Source>openlp/plugins/songs/forms/songbookdialog.py</Source>
<Source>openlp/plugins/songs/forms/topicsdialog.py</Source>
@ -111,8 +105,17 @@
<Source>openlp/migration/migratesongs.py</Source>
<Source>openlp/migration/display.py</Source>
<Source>openlp/migration/migratebibles.py</Source>
<Source>openlp/plugins/songs/lib/songclasses.py</Source>
<Source>openlp/plugins/songs/lib/songtables.py</Source>
<Source>openlp/plugins/songs/lib/tables.py</Source>
<Source>openlp/plugins/songs/lib/classes.py</Source>
<Source>openlp/plugins/songs/lib/manager.py</Source>
<Source>openlp/plugins/bibles/lib/classes.py</Source>
<Source>openlp/plugins/bibles/lib/tables.py</Source>
<Source>openlp/plugins/bibles/lib/manager.py</Source>
<Source>openlp/plugins/bibles/lib/common.py</Source>
<Source>openlp/plugins/songs/lib/meta.py</Source>
<Source>openlp/core/test/testplugins/deeper/__init__.py</Source>
<Source>openlp/core/test/testplugins/deeper/toodeep/__init__.py</Source>
<Source>openlp/core/test/testplugins/deeper/toodeep/plugin3toodeep.py</Source>
</Sources>
<Forms>
<Form>resources/forms/openlpexportform.ui</Form>
@ -148,7 +151,7 @@
</Others>
<MainScript>openlp.pyw</MainScript>
<Vcs>
<VcsType>PySvn</VcsType>
<VcsType>Subversion</VcsType>
<VcsOptions>
<dict>
<key>
@ -220,7 +223,7 @@
</key>
<value>
<list>
<string></string>
<string></string>
</list>
</value>
<key>

View File

@ -27,8 +27,6 @@ from songbookform import SongBookForm
from editsongdialog import Ui_EditSongDialog
from openlp.plugins.songs.lib.models import Session, Song, Author, Topic
class EditSongForm(QWidget, Ui_EditSongDialog):
"""
Class documentation goes here.
@ -61,10 +59,6 @@ class EditSongForm(QWidget, Ui_EditSongDialog):
self.AuthorsSelectionComboItem.addItem( i.display_name)
def load_song(self, songid):
if songid == None: # We have a new Song
self.song = Song()
else:
self.songid = songid
self.song = self.songmanager.get_song(songid)
self.TitleEditItem.setText(self.song.title)
self.LyricsTextEdit.setText(self.song.lyrics)

View File

@ -18,8 +18,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
from songmanager import SongManager
from songtable import Author
from manager import SongManager
#from xml import SongOpenXml
__all__ = ['SongManager', 'Author']
__all__ = ['SongManager']

View File

@ -16,8 +16,6 @@ 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):
"""
@ -58,14 +56,3 @@ 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

@ -23,7 +23,7 @@ import sys
from sqlalchemy import asc, desc
from openlp.plugins.songs.lib.models import init_models, metadata, session, \
songs_table, Song, Author, Topic
engine, songs_table, Song, Author, Topic
import logging
@ -47,15 +47,17 @@ class SongManager():
self.db_url = u''
db_type = self.config.get_config(u'db type')
if db_type == u'sqlite':
self.db_url = u'sqlite://' + self.config.get_data_path() + \
self.db_url = u'sqlite:///' + self.config.get_data_path() + \
u'/songs.sqlite'
print self.db_url
else:
self.db_url = db_type + 'u://' + \
self.config.get_config(u'db username') + u':' + \
self.config.get_config(u'db password') + u'@' + \
self.config.get_config(u'db hostname') + u'/' + \
self.config.get_config(u'db database')
init_models(self.db_url)
#print self.db_url
self.session = init_models(self.db_url)
if not songs_table.exists():
metadata.create_all()
log.debug( "Song Initialised")
@ -67,19 +69,19 @@ class SongManager():
"""
Returns the details of a song
"""
return session.query(Song).order_by(title).all()
return self.session.query(Song).order_by(title).all()
def search_song_title(self, keywords):
"""
Searches the song title for keywords.
"""
return session.query(Song).filter(search_title.like(u'%' + keywords + u'%'))
return self.session.query(Song).filter(search_title.like(u'%' + keywords + u'%'))
def search_song_lyrics(self, keywords):
"""
Searches the song lyrics for keywords.
"""
return session.query(Song).filter(search_lyrics.like(u'%' + keywords + u'%'))
return self.session.query(Song).filter(search_lyrics.like(u'%' + keywords + u'%'))
def get_song(self, id=None):
"""
@ -88,23 +90,23 @@ class SongManager():
if id is None:
return Song()
else:
return session.query(Song).get(id)
return self.session.query(Song).get(id)
def save_song(self, song):
"""
Saves a song to the database
"""
try:
session.add(song)
session.commit()
self.session.add(song)
self.session.commit()
return True
except:
return False
def delete_song(self, song):
try:
session.delete(song)
session.commit()
self.session.delete(song)
self.session.commit()
return True
except:
return False
@ -113,21 +115,21 @@ class SongManager():
"""
Returns a list of all the authors
"""
return session.query(Author).order_by(display_name).all()
return self.session.query(Author).order_by(Author.display_name).all()
def get_author(self, id):
"""
Details of the Author
"""
return session.query(Author).get(id)
return self.session.query(Author).get(id)
def save_author(self, author):
"""
Save the Author and refresh the cache
"""
try:
session.add(author)
session.commit()
self.session.add(author)
self.session.commit()
return True
except:
return False
@ -137,8 +139,8 @@ class SongManager():
Delete the author and refresh the author cache
"""
try:
session.delete(author)
session.commit()
self.session.delete(author)
self.session.commit()
return True
except:
return False

View File

@ -26,16 +26,16 @@ from openlp.plugins.songs.lib.classes import *
def init_models(url):
engine = create_engine(url)
metadata.bind = engine
session = scoped_session(sessionmaker(autoflush=True, autocommit=False,
bind=engine))
metadata.bind = engine
mapper(Author, authors_table)
mapper(Book, song_books_table)
mapper(Song, songs_table,
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)
mapper(Topic, topics_table)
return session

View File

@ -22,11 +22,10 @@ import logging
from PyQt4 import QtCore, QtGui
from openlp.core.resources import *
from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem
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.songclasses import *
class SongsPlugin(Plugin, PluginUtils):
global log
@ -123,9 +122,9 @@ class SongsPlugin(Plugin, PluginUtils):
self.SongListView.setObjectName("listView")
self.MediaManagerItem.PageLayout.addWidget(self.SongListView)
QtCore.QObject.connect(self.SearchTextButton, QtCore.SIGNAL("pressed()"), self.onSearchTextButton)
QtCore.QObject.connect(self.ClearTextButton, QtCore.SIGNAL("pressed()"), self.onClearTextButton)
QtCore.QObject.connect(self.SearchTextEdit, QtCore.SIGNAL("textChanged(const QString&)"), self.onSearchTextEdit)
QtCore.QObject.connect(self.SearchTextButton, QtCore.SIGNAL("pressed()"), self.onSearchTextButtonClick)
QtCore.QObject.connect(self.ClearTextButton, QtCore.SIGNAL("pressed()"), self.onClearTextButtonClick)
QtCore.QObject.connect(self.SearchTextEdit, QtCore.SIGNAL("textChanged(const QString&)"), self.onSearchTextEditChanged)
QtCore.QObject.connect(self.SongListView, QtCore.SIGNAL("itemPressed(QTableWidgetItem * item)"), self.onSongSelected)
@ -194,35 +193,37 @@ class SongsPlugin(Plugin, PluginUtils):
QtCore.QObject.connect(self.ExportOpenSongItem, QtCore.SIGNAL("triggered()"), self.onExportOpenSongItemClicked)
def initialise(self):
self.SearchTypeComboBox.addItem("Titles")
self.SearchTypeComboBox.addItem("Lyrics")
self.SearchTypeComboBox.addItem("Authors")
self.SearchTypeComboBox.addItem(u'Titles')
self.SearchTypeComboBox.addItem(u'Lyrics')
self.SearchTypeComboBox.addItem(u'Authors')
def onClearTextButton(self):
def onClearTextButtonClick(self):
"""
Clear the search text.
"""
self.SearchTextEdit.clear()
def onSearchTextEdit(self):
sl = 3
if self.SearchTypeComboBox.currentText()=="Lyrics":
sl = 7
if len(self.SearchTextEdit.displayText()) > sl: # only search if > 3 characters
self.onSearchTextButton()
def onSearchTextEditChanged(self, text):
#sl = 3
#if self.SearchTypeComboBox.currentText() == u'Lyrics':
# sl = 7
#if len(text) > sl: # only search if > 3 characters
self.onSearchTextButtonClick()
def onSearchTextButton(self):
searchtext = str(self.SearchTextEdit.displayText() )
searchresults = []
ct = self.SearchTypeComboBox.currentText()
if self.SearchTypeComboBox.currentText()=="Titles":
def onSearchTextButtonClick(self):
search_keywords = str(self.SearchTextEdit.displayText())
search_results = []
search_type = self.SearchTypeComboBox.currentText()
if search_type == u'Titles':
log.debug("Titles Search")
searchresults = self.songmanager.get_song_from_title(searchtext)
elif self.SearchTypeComboBox.currentText()=="Lyrics":
search_results = self.songmanager.search_song_title(search_keywords)
elif search_type == u'Lyrics':
log.debug("Lyrics Search")
searchresults = self.songmanager.get_song_from_lyrics(searchtext)
elif self.SearchTypeComboBox.currentText()=="Authors":
searchresults = self.songmanager.search_song_lyrics(search_keywords)
elif search_type == u'Authors':
log.debug("Authors Search")
searchresults = self.songmanager.get_song_from_author(searchtext)
self._display_results(searchresults)
#searchresults = self.songmanager.get_song_from_author(searchtext)
self._display_results(search_results)
def onSongSelected(self, item):
print item