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

Proposed by Tim Bentley
Status: Merged
Approved by: Raoul Snyman
Approved revision: 1552
Merged at revision: 1725
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 Approve
Review via email: mp+73130@code.launchpad.net

This proposal supersedes a proposal from 2011-08-26.

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 : Posted in a previous version of this proposal

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

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

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