From 71a3ac4c78712d0a54e00a44318dc0823c264b5b Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 13 Mar 2009 06:12:22 +0000 Subject: [PATCH] Start to add data to database bzr-revno: 412 --- openlp/plugins/custom/forms/editcustomform.py | 17 ++++++- openlp/plugins/custom/lib/__init__.py | 3 +- openlp/plugins/custom/lib/manager.py | 49 ++++++++----------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index 21ec89d9a..f16685957 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -20,6 +20,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA from PyQt4 import Qt, QtCore, QtGui from editcustomdialog import Ui_customEditDialog +from openlp.core.lib import SongXMLBuilder +from openlp.plugins.custom.lib.models import CustomSlide class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): """ @@ -55,9 +57,20 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): def accept(self): self.validate() - for i in range (0, self.VerseListView.count()): - print self.VerseListView.item(i).text() if self.valid: + sxml=SongXMLBuilder() + sxml.new_document() + sxml.add_lyrics_to_song() + count = 1 + for i in range (0, self.VerseListView.count()): + sxml.add_verse_to_lyrics(u'custom', str(count), str(self.VerseListView.item(i).text())) + count += 1 + sxml.dump_xml() + customSlide = CustomSlide() + customSlide.title = str(self.TitleEdit.displayText()) + customSlide.text = str(sxml.extract_xml()) + customSlide.credits = str(self.CreditEdit.displayText()) + self.custommanager.save_slide(customSlide) self.close() def rejected(self): diff --git a/openlp/plugins/custom/lib/__init__.py b/openlp/plugins/custom/lib/__init__.py index 3d919f5a3..3c05de4b3 100644 --- a/openlp/plugins/custom/lib/__init__.py +++ b/openlp/plugins/custom/lib/__init__.py @@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA from manager import CustomManager from customtab import CustomTab from mediaitem import CustomMediaItem +from textlistdata import TextListData -__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem'] +__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem', 'TextListData'] diff --git a/openlp/plugins/custom/lib/manager.py b/openlp/plugins/custom/lib/manager.py index 46ea275ae..fc28a226a 100644 --- a/openlp/plugins/custom/lib/manager.py +++ b/openlp/plugins/custom/lib/manager.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley +Portions copyright (c) 2008 - 2009 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 @@ -64,42 +64,33 @@ class CustomManager(): # def process_dialog(self, dialogobject): # self.dialogobject = dialogobject # -# def get_songs(self): -# """ -# Returns the details of a song -# """ -# return self.session.query(Song).order_by(title).all() -# -# def search_song_title(self, keywords): -# """ -# Searches the song title for keywords. -# """ -# return self.session.query(Song).filter(Song.search_title.like(u'%' + keywords + u'%')).order_by(Song.search_title.asc()).all() -# -# def search_song_lyrics(self, keywords): -# """ -# Searches the song lyrics for keywords. -# """ -# return self.session.query(Song).filter(Song.search_lyrics.like(u'%' + keywords + u'%')).order_by(Song.search_lyrics.asc()).all() -# -# def get_song(self, id=None): -# """ -# Returns the details of a song -# """ -# if id is None: -# return Song() -# else: -# return self.session.query(Song).get(id) -# - def save_slides(self, customslide): + def get_all_slides(self): + """ + Returns the details of a song + """ + return self.session.query(CustomSlide).order_by(CustomSlide.title).all() + + def get_custom(self, id=None): + """ + Returns the details of a song + """ + if id is None: + return CustomeSlide() + else: + return self.session.query(CustomSlide).get(id) + + def save_slide(self, customslide): """ Saves a song to the database """ + log.debug('Custom Slide added') try: self.session.add(customslide) self.session.commit() + log.debug('Custom Slide saved') return True except: + log.debug('Custom Slide failed') return False # # def delete_song(self, song):