← Back to team overview

openlp-core team mailing list archive

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

 

Tim Bentley has proposed merging lp:~trb143/openlp/bug-825812 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #825812 in OpenLP: "SongUsage plugin should record printed songs, etc."
  https://bugs.launchpad.net/openlp/+bug/825812

For more details, see:
https://code.launchpad.net/~trb143/openlp/bug-825812/+merge/73094

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)
-- 
https://code.launchpad.net/~trb143/openlp/bug-825812/+merge/73094
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/bug-825812 into lp:openlp.
=== 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-26 19:39:41 +0000
@@ -73,6 +73,13 @@
         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 @@
     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 @@
             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

=== modified file 'openlp/plugins/songs/lib/upgrade.py'
--- openlp/plugins/songs/lib/upgrade.py	2011-08-25 20:14:02 +0000
+++ openlp/plugins/songs/lib/upgrade.py	2011-08-26 19:39:41 +0000
@@ -25,8 +25,8 @@
 # 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
@@ -57,7 +57,7 @@
     """
     Version 1 upgrade.
 
-    This upgrade removes the many-to-many relationship between songs and 
+    This upgrade removes the many-to-many relationship between songs and
     media_files and replaces it with a one-to-many, which is far more
     representative of the real relationship between the two entities.
 

=== 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-26 19:39:41 +0000
@@ -117,9 +117,11 @@
         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',

=== 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-26 19:39:41 +0000
@@ -56,7 +56,9 @@
         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)

=== 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-26 19:39:41 +0000
@@ -0,0 +1,59 @@
+# -*- 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, ForeignKey, Table, types
+from migrate import changeset
+from migrate.changeset.constraint import ForeignKeyConstraint
+
+__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)

=== 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-26 19:39:41 +0000
@@ -37,6 +37,7 @@
 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 @@
 
     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 @@
         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 @@
             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 @@
         self.songUsageStatus.blockSignals(False)
 
 
-    def onReceiveSongUsage(self, item):
-        """
-        Song Usage for live song from SlideController
-        """
+    def displaySongUsage(self, item):
+        """
+        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 @@
             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):


Follow ups