Merge lp:~trb143/openlp/bug-825812 into lp:openlp

Proposed by Tim Bentley
Status: Superseded
Proposed branch: lp:~trb143/openlp/bug-825812
Merge into: lp:openlp
Diff against target: 220 lines (+95/-21)
5 files modified
openlp/core/lib/db.py (+8/-8)
openlp/plugins/songusage/forms/songusagedetailform.py (+5/-3)
openlp/plugins/songusage/lib/db.py (+3/-1)
openlp/plugins/songusage/lib/upgrade.py (+58/-0)
openlp/plugins/songusage/songusageplugin.py (+21/-9)
To merge this branch: bzr merge lp:~trb143/openlp/bug-825812
Reviewer Review Type Date Requested Status
Raoul Snyman Needs Fixing
Review via email: mp+73094@code.launchpad.net

This proposal has been superseded by a proposal from 2011-08-27.

Description of the change

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 (Thanks Raoul)

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

You don't use ForeignKey or ForeignKeyConstraint... might I suggest you remove those unnecessary imports?

review: Needs Fixing
lp:~trb143/openlp/bug-825812 updated
1551. By Tim Bentley

Remove extra imports

1552. By Tim Bentley

Remove extra imports 2

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/lib/db.py'
--- openlp/core/lib/db.py 2011-08-25 20:02:55 +0000
+++ openlp/core/lib/db.py 2011-08-27 06:13:26 +0000
@@ -73,6 +73,13 @@
73 The python module that contains the upgrade instructions.73 The python module that contains the upgrade instructions.
74 """74 """
75 session, metadata = init_db(url)75 session, metadata = init_db(url)
76
77 class Metadata(BaseModel):
78 """
79 Provides a class for the metadata table.
80 """
81 pass
82
76 tables = upgrade.upgrade_setup(metadata)83 tables = upgrade.upgrade_setup(metadata)
77 metadata_table = Table(u'metadata', metadata,84 metadata_table = Table(u'metadata', metadata,
78 Column(u'key', types.Unicode(64), primary_key=True),85 Column(u'key', types.Unicode(64), primary_key=True),
@@ -103,6 +110,7 @@
103 session.commit()110 session.commit()
104 return int(version_meta.value), upgrade.__version__111 return int(version_meta.value), upgrade.__version__
105112
113
106def delete_database(plugin_name, db_file_name=None):114def delete_database(plugin_name, db_file_name=None):
107 """115 """
108 Remove a database file from the system.116 Remove a database file from the system.
@@ -138,14 +146,6 @@
138 instance.__setattr__(key, value)146 instance.__setattr__(key, value)
139 return instance147 return instance
140148
141
142class Metadata(BaseModel):
143 """
144 Provides a class for the metadata table.
145 """
146 pass
147
148
149class Manager(object):149class Manager(object):
150 """150 """
151 Provide generic object persistence management151 Provide generic object persistence management
152152
=== modified file 'openlp/plugins/songs/lib/upgrade.py'
=== modified file 'openlp/plugins/songusage/forms/songusagedetailform.py'
--- openlp/plugins/songusage/forms/songusagedetailform.py 2011-06-12 16:02:52 +0000
+++ openlp/plugins/songusage/forms/songusagedetailform.py 2011-08-27 06:13:26 +0000
@@ -117,9 +117,11 @@
117 try:117 try:
118 fileHandle = open(outname, u'w')118 fileHandle = open(outname, u'w')
119 for instance in usage:119 for instance in usage:
120 record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % (120 record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",' \
121 instance.usagedate, instance.usagetime, instance.title,121 u'\"%s\",\"%s\"\n' % ( instance.usagedate,
122 instance.copyright, instance.ccl_number, instance.authors)122 instance.usagetime, instance.title, instance.copyright,
123 instance.ccl_number, instance.authors,
124 instance.plugin_name, instance.source)
123 fileHandle.write(record.encode(u'utf-8'))125 fileHandle.write(record.encode(u'utf-8'))
124 Receiver.send_message(u'openlp_information_message', {126 Receiver.send_message(u'openlp_information_message', {
125 u'title': translate('SongUsagePlugin.SongUsageDetailForm',127 u'title': translate('SongUsagePlugin.SongUsageDetailForm',
126128
=== modified file 'openlp/plugins/songusage/lib/db.py'
--- openlp/plugins/songusage/lib/db.py 2011-06-12 16:02:52 +0000
+++ openlp/plugins/songusage/lib/db.py 2011-08-27 06:13:26 +0000
@@ -56,7 +56,9 @@
56 Column(u'title', types.Unicode(255), nullable=False),56 Column(u'title', types.Unicode(255), nullable=False),
57 Column(u'authors', types.Unicode(255), nullable=False),57 Column(u'authors', types.Unicode(255), nullable=False),
58 Column(u'copyright', types.Unicode(255)),58 Column(u'copyright', types.Unicode(255)),
59 Column(u'ccl_number', types.Unicode(65))59 Column(u'ccl_number', types.Unicode(65)),
60 Column(u'plugin_name', types.Unicode(20)),
61 Column(u'source', types.Unicode(10))
60 )62 )
6163
62 mapper(SongUsageItem, songusage_table)64 mapper(SongUsageItem, songusage_table)
6365
=== added file 'openlp/plugins/songusage/lib/upgrade.py'
--- openlp/plugins/songusage/lib/upgrade.py 1970-01-01 00:00:00 +0000
+++ openlp/plugins/songusage/lib/upgrade.py 2011-08-27 06:13:26 +0000
@@ -0,0 +1,58 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2011 Raoul Snyman #
8# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
9# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
10# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
11# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
12# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
13# --------------------------------------------------------------------------- #
14# This program is free software; you can redistribute it and/or modify it #
15# under the terms of the GNU General Public License as published by the Free #
16# Software Foundation; version 2 of the License. #
17# #
18# This program is distributed in the hope that it will be useful, but WITHOUT #
19# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
20# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
21# more details. #
22# #
23# You should have received a copy of the GNU General Public License along #
24# with this program; if not, write to the Free Software Foundation, Inc., 59 #
25# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
26###############################################################################
27"""
28The :mod:`upgrade` module provides a way for the database and schema that is the
29backend for the SongsUsage plugin
30"""
31
32from sqlalchemy import Column, Table, types
33from migrate import changeset
34
35__version__ = 1
36
37def upgrade_setup(metadata):
38 """
39 Set up the latest revision all tables, with reflection, needed for the
40 upgrade process. If you want to drop a table, you need to remove it from
41 here, and add it to your upgrade function.
42 """
43 tables = {
44 u'songusage_data': Table(u'songusage_data', metadata, autoload=True)
45 }
46 return tables
47
48
49def upgrade_1(session, metadata, tables):
50 """
51 Version 1 upgrade.
52
53 This upgrade adds two new fields to the songusage database
54 """
55 Column(u'plugin_name', types.Unicode(20), default=u'') \
56 .create(table=tables[u'songusage_data'], populate_default=True)
57 Column(u'source', types.Unicode(10), default=u'') \
58 .create(table=tables[u'songusage_data'], populate_default=True)
059
=== modified file 'openlp/plugins/songusage/songusageplugin.py'
--- openlp/plugins/songusage/songusageplugin.py 2011-08-21 04:51:19 +0000
+++ openlp/plugins/songusage/songusageplugin.py 2011-08-27 06:13:26 +0000
@@ -37,6 +37,7 @@
37from openlp.core.utils.actions import ActionList37from openlp.core.utils.actions import ActionList
38from openlp.plugins.songusage.forms import SongUsageDetailForm, \38from openlp.plugins.songusage.forms import SongUsageDetailForm, \
39 SongUsageDeleteForm39 SongUsageDeleteForm
40from openlp.plugins.songusage.lib import upgrade
40from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem41from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem
4142
42log = logging.getLogger(__name__)43log = logging.getLogger(__name__)
@@ -46,11 +47,11 @@
4647
47 def __init__(self, plugin_helpers):48 def __init__(self, plugin_helpers):
48 Plugin.__init__(self, u'songusage', plugin_helpers)49 Plugin.__init__(self, u'songusage', plugin_helpers)
50 self.manager = Manager(u'songusage', init_schema, upgrade_mod=upgrade)
49 self.weight = -451 self.weight = -4
50 self.icon = build_icon(u':/plugins/plugin_songusage.png')52 self.icon = build_icon(u':/plugins/plugin_songusage.png')
51 self.activeIcon = build_icon(u':/songusage/song_usage_active.png')53 self.activeIcon = build_icon(u':/songusage/song_usage_active.png')
52 self.inactiveIcon = build_icon(u':/songusage/song_usage_inactive.png')54 self.inactiveIcon = build_icon(u':/songusage/song_usage_inactive.png')
53 self.manager = None
54 self.songUsageActive = False55 self.songUsageActive = False
5556
56 def addToolsMenuItem(self, tools_menu):57 def addToolsMenuItem(self, tools_menu):
@@ -121,10 +122,10 @@
121 Plugin.initialise(self)122 Plugin.initialise(self)
122 QtCore.QObject.connect(Receiver.get_receiver(),123 QtCore.QObject.connect(Receiver.get_receiver(),
123 QtCore.SIGNAL(u'slidecontroller_live_started'),124 QtCore.SIGNAL(u'slidecontroller_live_started'),
124 self.onReceiveSongUsage)125 self.displaySongUsage)
125 QtCore.QObject.connect(Receiver.get_receiver(),126 QtCore.QObject.connect(Receiver.get_receiver(),
126 QtCore.SIGNAL(u'print_service_started'),127 QtCore.SIGNAL(u'print_service_started'),
127 self.onReceiveSongUsage)128 self.printSongUsage)
128 self.songUsageActive = QtCore.QSettings().value(129 self.songUsageActive = QtCore.QSettings().value(
129 self.settingsSection + u'/active',130 self.settingsSection + u'/active',
130 QtCore.QVariant(False)).toBool()131 QtCore.QVariant(False)).toBool()
@@ -137,8 +138,6 @@
137 translate('SongUsagePlugin', 'Song Usage'))138 translate('SongUsagePlugin', 'Song Usage'))
138 action_list.add_action(self.songUsageReport,139 action_list.add_action(self.songUsageReport,
139 translate('SongUsagePlugin', 'Song Usage'))140 translate('SongUsagePlugin', 'Song Usage'))
140 if self.manager is None:
141 self.manager = Manager(u'songusage', init_schema)
142 self.songUsageDeleteForm = SongUsageDeleteForm(self.manager,141 self.songUsageDeleteForm = SongUsageDeleteForm(self.manager,
143 self.formparent)142 self.formparent)
144 self.songUsageDetailForm = SongUsageDetailForm(self, self.formparent)143 self.songUsageDetailForm = SongUsageDetailForm(self, self.formparent)
@@ -197,10 +196,21 @@
197 self.songUsageStatus.blockSignals(False)196 self.songUsageStatus.blockSignals(False)
198197
199198
200 def onReceiveSongUsage(self, item):199 def displaySongUsage(self, item):
201 """200 """
202 Song Usage for live song from SlideController201 Song Usage for which has been displayed
203 """202 """
203 self._add_song_usage(unicode(translate('SongUsagePlugin',
204 'display')), item)
205
206 def printSongUsage(self, item):
207 """
208 Song Usage for which has been printed
209 """
210 self._add_song_usage(unicode(translate('SongUsagePlugin',
211 'printed')), item)
212
213 def _add_song_usage(self, source, item):
204 audit = item[0].audit214 audit = item[0].audit
205 if self.songUsageActive and audit:215 if self.songUsageActive and audit:
206 song_usage_item = SongUsageItem()216 song_usage_item = SongUsageItem()
@@ -210,6 +220,8 @@
210 song_usage_item.copyright = audit[2]220 song_usage_item.copyright = audit[2]
211 song_usage_item.ccl_number = audit[3]221 song_usage_item.ccl_number = audit[3]
212 song_usage_item.authors = u' '.join(audit[1])222 song_usage_item.authors = u' '.join(audit[1])
223 song_usage_item.plugin_name = item[0].name
224 song_usage_item.source = source
213 self.manager.save_object(song_usage_item)225 self.manager.save_object(song_usage_item)
214226
215 def onSongUsageDelete(self):227 def onSongUsageDelete(self):