add field and usage

This commit is contained in:
Tim Bentley 2011-12-03 09:05:01 +00:00
parent 4b60c0bf7f
commit 624216a1b8
6 changed files with 31 additions and 5 deletions

View File

@ -361,6 +361,10 @@ class Manager(object):
``object_class``
The type of object to delete
``filter_clause``
The filter governing selection of objects to return. Defaults to
None.
"""
try:
query = self.session.query(object_class)

View File

@ -199,7 +199,8 @@ def init_schema(url):
Column(u'search_lyrics', types.UnicodeText, nullable=False),
Column(u'create_date', types.DateTime(), default=func.now()),
Column(u'last_modified', types.DateTime(), default=func.now(),
onupdate=func.now())
onupdate=func.now()),
Column(u'temporary', types.Unicode(1), default=u'N')
)
# Definition of the "topics" table

View File

@ -270,6 +270,9 @@ class SongMediaItem(MediaManagerItem):
searchresults.sort(
cmp=locale.strcoll, key=lambda song: song.title.lower())
for song in searchresults:
# Do not display temporary songs
if song.temporary == u'Y':
break
author_list = [author.display_name for author in song.authors]
song_title = unicode(song.title)
song_detail = u'%s (%s)' % (song_title, u', '.join(author_list))
@ -286,6 +289,9 @@ class SongMediaItem(MediaManagerItem):
self.listView.clear()
for author in searchresults:
for song in author.songs:
# Do not display temporary songs
if song.temporary == u'Y':
break
song_detail = u'%s (%s)' % (author.display_name, song.title)
song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
@ -561,7 +567,8 @@ class SongMediaItem(MediaManagerItem):
self.onSearchTextButtonClick()
else:
# Make sure we temporary import formatting tags.
self.openLyrics.xml_to_song(item.xml_version, True)
song = self.openLyrics.xml_to_song(item.xml_version, True)
#editId = song.id
# Update service with correct song id.
if editId:
Receiver.send_message(u'service_item_update',

View File

@ -34,7 +34,9 @@ from sqlalchemy.sql.expression import func
from migrate import changeset
from migrate.changeset.constraint import ForeignKeyConstraint
__version__ = 2
from openlp.plugins.songs.lib.db import Song
__version__ = 3
def upgrade_setup(metadata):
"""
@ -86,4 +88,13 @@ def upgrade_2(session, metadata, tables):
.create(table=tables[u'songs'])
Column(u'last_modified', types.DateTime(), default=func.now())\
.create(table=tables[u'songs'])
def upgrade_3(session, metadata, tables):
"""
Version 3 upgrade.
This upgrade adds a temporary song flag to the songs table
"""
Column(u'temporary', types.Unicode(1), default=u'N')\
.create(table=tables[u'songs'])

View File

@ -372,13 +372,13 @@ class OpenLyrics(object):
# Formatting tags are new in OpenLyrics 0.8
if float(song_xml.get(u'version')) > 0.7:
self._process_formatting_tags(song_xml, parse_and_not_save)
if parse_and_not_save:
return
song = Song()
# Values will be set when cleaning the song.
song.search_lyrics = u''
song.verse_order = u''
song.search_title = u''
if parse_and_not_save:
song.temporary = u'Y'
self._process_copyright(properties, song)
self._process_cclinumber(properties, song)
self._process_titles(properties, song)

View File

@ -261,6 +261,9 @@ class SongsPlugin(Plugin):
Time to tidy up on exit
"""
log.info(u'Songs Finalising')
# Remove temporary songs
self.manager.delete_all_objects(Song, Song.temporary == u'Y')
# Clean up files and connections
self.manager.finalise()
self.songImportItem.setVisible(False)
self.songExportItem.setVisible(False)