Update songusage database to add plugin and what type of access.

Amend triggers to record the correct data
Update report to output the new data items.

Apply fix in bug to allow Meda_data tables to be defined in core

bzr-revno: 1725
This commit is contained in:
Tim Bentley 2011-08-27 09:15:55 +01:00
commit 9949fba4ae
5 changed files with 93 additions and 19 deletions

View File

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

View File

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

View File

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

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

View File

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