forked from openlp/openlp
r1726
This commit is contained in:
commit
65630c6853
@ -73,6 +73,13 @@ def upgrade_db(url, upgrade):
|
||||
The python module that contains the upgrade instructions.
|
||||
"""
|
||||
session, metadata = init_db(url)
|
||||
|
||||
class Metadata(BaseModel):
|
||||
"""
|
||||
Provides a class for the metadata table.
|
||||
"""
|
||||
pass
|
||||
|
||||
tables = upgrade.upgrade_setup(metadata)
|
||||
metadata_table = Table(u'metadata', metadata,
|
||||
Column(u'key', types.Unicode(64), primary_key=True),
|
||||
@ -103,6 +110,7 @@ def upgrade_db(url, upgrade):
|
||||
session.commit()
|
||||
return int(version_meta.value), upgrade.__version__
|
||||
|
||||
|
||||
def delete_database(plugin_name, db_file_name=None):
|
||||
"""
|
||||
Remove a database file from the system.
|
||||
@ -138,14 +146,6 @@ class BaseModel(object):
|
||||
instance.__setattr__(key, value)
|
||||
return instance
|
||||
|
||||
|
||||
class Metadata(BaseModel):
|
||||
"""
|
||||
Provides a class for the metadata table.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Manager(object):
|
||||
"""
|
||||
Provide generic object persistence management
|
||||
|
@ -170,8 +170,8 @@ class SongExportForm(OpenLPWizard):
|
||||
translate('OpenLP.Ui', 'Welcome to the Song Export Wizard'))
|
||||
self.informationLabel.setText(
|
||||
translate('SongsPlugin.ExportWizardForm', 'This wizard will help to'
|
||||
' export your songs to the open and free OpenLyrics worship song '
|
||||
'format.'))
|
||||
' export your songs to the open and free <strong>OpenLyrics'
|
||||
'</strong> worship song format.'))
|
||||
self.availableSongsPage.setTitle(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Select Songs'))
|
||||
self.availableSongsPage.setSubTitle(
|
||||
@ -285,7 +285,9 @@ class SongExportForm(OpenLPWizard):
|
||||
self, songs, unicode(self.directoryLineEdit.text()))
|
||||
if exporter.do_export():
|
||||
self.progressLabel.setText(
|
||||
translate('SongsPlugin.SongExportForm', 'Finished export.'))
|
||||
translate('SongsPlugin.SongExportForm', 'Finished export. To '
|
||||
'import these files use the <strong>OpenLyrics</strong> '
|
||||
'importer.'))
|
||||
else:
|
||||
self.progressLabel.setText(
|
||||
translate('SongsPlugin.SongExportForm',
|
||||
|
@ -31,6 +31,7 @@ the Songs plugin
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Table, types
|
||||
from sqlalchemy.orm import mapper, relation
|
||||
from sqlalchemy.sql.expression import func
|
||||
|
||||
from openlp.core.lib.db import BaseModel, init_db
|
||||
|
||||
@ -195,7 +196,10 @@ def init_schema(url):
|
||||
Column(u'song_number', types.Unicode(64)),
|
||||
Column(u'theme_name', types.Unicode(128)),
|
||||
Column(u'search_title', types.Unicode(255), index=True, nullable=False),
|
||||
Column(u'search_lyrics', types.UnicodeText, nullable=False)
|
||||
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())
|
||||
)
|
||||
|
||||
# Definition of the "topics" table
|
||||
|
@ -25,15 +25,16 @@
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
"""
|
||||
The :mod:`upgrade` module provides a way for the database and schema that is the backend for
|
||||
the Songs plugin
|
||||
The :mod:`upgrade` module provides a way for the database and schema that is the
|
||||
backend for the Songs plugin
|
||||
"""
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Table, types
|
||||
from sqlalchemy.sql.expression import func
|
||||
from migrate import changeset
|
||||
from migrate.changeset.constraint import ForeignKeyConstraint
|
||||
|
||||
__version__ = 1
|
||||
__version__ = 2
|
||||
|
||||
def upgrade_setup(metadata):
|
||||
"""
|
||||
@ -75,3 +76,13 @@ def upgrade_1(session, metadata, tables):
|
||||
ForeignKeyConstraint([u'song_id'], [u'songs.id'],
|
||||
table=tables[u'media_files']).create()
|
||||
|
||||
def upgrade_2(session, metadata, tables):
|
||||
"""
|
||||
Version 2 upgrade.
|
||||
|
||||
This upgrade adds a create_date and last_modified date to the songs table
|
||||
"""
|
||||
Column(u'create_date', types.DateTime(), default=func.now())\
|
||||
.create(table=tables[u'songs'], populate_default=True)
|
||||
Column(u'last_modified', types.DateTime(), default=func.now())\
|
||||
.create(table=tables[u'songs'], populate_default=True)
|
||||
|
@ -117,9 +117,11 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
||||
try:
|
||||
fileHandle = open(outname, u'w')
|
||||
for instance in usage:
|
||||
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % (
|
||||
instance.usagedate, instance.usagetime, instance.title,
|
||||
instance.copyright, instance.ccl_number, instance.authors)
|
||||
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",' \
|
||||
u'\"%s\",\"%s\"\n' % ( instance.usagedate,
|
||||
instance.usagetime, instance.title, instance.copyright,
|
||||
instance.ccl_number, instance.authors,
|
||||
instance.plugin_name, instance.source)
|
||||
fileHandle.write(record.encode(u'utf-8'))
|
||||
Receiver.send_message(u'openlp_information_message', {
|
||||
u'title': translate('SongUsagePlugin.SongUsageDetailForm',
|
||||
|
@ -56,7 +56,9 @@ def init_schema(url):
|
||||
Column(u'title', types.Unicode(255), nullable=False),
|
||||
Column(u'authors', types.Unicode(255), nullable=False),
|
||||
Column(u'copyright', types.Unicode(255)),
|
||||
Column(u'ccl_number', types.Unicode(65))
|
||||
Column(u'ccl_number', types.Unicode(65)),
|
||||
Column(u'plugin_name', types.Unicode(20)),
|
||||
Column(u'source', types.Unicode(10))
|
||||
)
|
||||
|
||||
mapper(SongUsageItem, songusage_table)
|
||||
|
58
openlp/plugins/songusage/lib/upgrade.py
Normal file
58
openlp/plugins/songusage/lib/upgrade.py
Normal file
@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2011 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
|
||||
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
|
||||
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# 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 #
|
||||
###############################################################################
|
||||
"""
|
||||
The :mod:`upgrade` module provides a way for the database and schema that is the
|
||||
backend for the SongsUsage plugin
|
||||
"""
|
||||
|
||||
from sqlalchemy import Column, Table, types
|
||||
from migrate import changeset
|
||||
|
||||
__version__ = 1
|
||||
|
||||
def upgrade_setup(metadata):
|
||||
"""
|
||||
Set up the latest revision all tables, with reflection, needed for the
|
||||
upgrade process. If you want to drop a table, you need to remove it from
|
||||
here, and add it to your upgrade function.
|
||||
"""
|
||||
tables = {
|
||||
u'songusage_data': Table(u'songusage_data', metadata, autoload=True)
|
||||
}
|
||||
return tables
|
||||
|
||||
|
||||
def upgrade_1(session, metadata, tables):
|
||||
"""
|
||||
Version 1 upgrade.
|
||||
|
||||
This upgrade adds two new fields to the songusage database
|
||||
"""
|
||||
Column(u'plugin_name', types.Unicode(20), default=u'') \
|
||||
.create(table=tables[u'songusage_data'], populate_default=True)
|
||||
Column(u'source', types.Unicode(10), default=u'') \
|
||||
.create(table=tables[u'songusage_data'], populate_default=True)
|
@ -37,6 +37,7 @@ from openlp.core.lib.ui import base_action, shortcut_action
|
||||
from openlp.core.utils.actions import ActionList
|
||||
from openlp.plugins.songusage.forms import SongUsageDetailForm, \
|
||||
SongUsageDeleteForm
|
||||
from openlp.plugins.songusage.lib import upgrade
|
||||
from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -46,11 +47,11 @@ class SongUsagePlugin(Plugin):
|
||||
|
||||
def __init__(self, plugin_helpers):
|
||||
Plugin.__init__(self, u'songusage', plugin_helpers)
|
||||
self.manager = Manager(u'songusage', init_schema, upgrade_mod=upgrade)
|
||||
self.weight = -4
|
||||
self.icon = build_icon(u':/plugins/plugin_songusage.png')
|
||||
self.activeIcon = build_icon(u':/songusage/song_usage_active.png')
|
||||
self.inactiveIcon = build_icon(u':/songusage/song_usage_inactive.png')
|
||||
self.manager = None
|
||||
self.songUsageActive = False
|
||||
|
||||
def addToolsMenuItem(self, tools_menu):
|
||||
@ -121,10 +122,10 @@ class SongUsagePlugin(Plugin):
|
||||
Plugin.initialise(self)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'slidecontroller_live_started'),
|
||||
self.onReceiveSongUsage)
|
||||
self.displaySongUsage)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'print_service_started'),
|
||||
self.onReceiveSongUsage)
|
||||
self.printSongUsage)
|
||||
self.songUsageActive = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/active',
|
||||
QtCore.QVariant(False)).toBool()
|
||||
@ -137,8 +138,6 @@ class SongUsagePlugin(Plugin):
|
||||
translate('SongUsagePlugin', 'Song Usage'))
|
||||
action_list.add_action(self.songUsageReport,
|
||||
translate('SongUsagePlugin', 'Song Usage'))
|
||||
if self.manager is None:
|
||||
self.manager = Manager(u'songusage', init_schema)
|
||||
self.songUsageDeleteForm = SongUsageDeleteForm(self.manager,
|
||||
self.formparent)
|
||||
self.songUsageDetailForm = SongUsageDetailForm(self, self.formparent)
|
||||
@ -197,10 +196,21 @@ class SongUsagePlugin(Plugin):
|
||||
self.songUsageStatus.blockSignals(False)
|
||||
|
||||
|
||||
def onReceiveSongUsage(self, item):
|
||||
def displaySongUsage(self, item):
|
||||
"""
|
||||
Song Usage for live song from SlideController
|
||||
Song Usage for which has been displayed
|
||||
"""
|
||||
self._add_song_usage(unicode(translate('SongUsagePlugin',
|
||||
'display')), item)
|
||||
|
||||
def printSongUsage(self, item):
|
||||
"""
|
||||
Song Usage for which has been printed
|
||||
"""
|
||||
self._add_song_usage(unicode(translate('SongUsagePlugin',
|
||||
'printed')), item)
|
||||
|
||||
def _add_song_usage(self, source, item):
|
||||
audit = item[0].audit
|
||||
if self.songUsageActive and audit:
|
||||
song_usage_item = SongUsageItem()
|
||||
@ -210,6 +220,8 @@ class SongUsagePlugin(Plugin):
|
||||
song_usage_item.copyright = audit[2]
|
||||
song_usage_item.ccl_number = audit[3]
|
||||
song_usage_item.authors = u' '.join(audit[1])
|
||||
song_usage_item.plugin_name = item[0].name
|
||||
song_usage_item.source = source
|
||||
self.manager.save_object(song_usage_item)
|
||||
|
||||
def onSongUsageDelete(self):
|
||||
|
Loading…
Reference in New Issue
Block a user