forked from openlp/openlp
Clean up Song Usage
This commit is contained in:
parent
68d8f58b5c
commit
b5c2659506
|
@ -34,7 +34,15 @@ from openlp.core.lib.ui import create_button_box
|
||||||
|
|
||||||
|
|
||||||
class Ui_SongUsageDeleteDialog(object):
|
class Ui_SongUsageDeleteDialog(object):
|
||||||
|
"""
|
||||||
|
The Song Usage delete dialog
|
||||||
|
"""
|
||||||
def setupUi(self, song_usage_delete_dialog):
|
def setupUi(self, song_usage_delete_dialog):
|
||||||
|
"""
|
||||||
|
Setup the UI
|
||||||
|
|
||||||
|
:param song_usage_delete_dialog:
|
||||||
|
"""
|
||||||
song_usage_delete_dialog.setObjectName('song_usage_delete_dialog')
|
song_usage_delete_dialog.setObjectName('song_usage_delete_dialog')
|
||||||
song_usage_delete_dialog.resize(291, 243)
|
song_usage_delete_dialog.resize(291, 243)
|
||||||
self.vertical_layout = QtGui.QVBoxLayout(song_usage_delete_dialog)
|
self.vertical_layout = QtGui.QVBoxLayout(song_usage_delete_dialog)
|
||||||
|
@ -55,8 +63,12 @@ class Ui_SongUsageDeleteDialog(object):
|
||||||
self.retranslateUi(song_usage_delete_dialog)
|
self.retranslateUi(song_usage_delete_dialog)
|
||||||
|
|
||||||
def retranslateUi(self, song_usage_delete_dialog):
|
def retranslateUi(self, song_usage_delete_dialog):
|
||||||
|
"""
|
||||||
|
Retranslate the strings
|
||||||
|
:param song_usage_delete_dialog:
|
||||||
|
"""
|
||||||
song_usage_delete_dialog.setWindowTitle(
|
song_usage_delete_dialog.setWindowTitle(
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Song Usage Data'))
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Song Usage Data'))
|
||||||
self.delete_label.setText(
|
self.delete_label.setText(
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Select the date up to which the song usage data '
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Select the date up to which the song usage data '
|
||||||
'should be deleted. All data recorded before this date will be permanently deleted.'))
|
'should be deleted. \nAll data recorded before this date will be permanently deleted.'))
|
||||||
|
|
|
@ -48,19 +48,25 @@ class SongUsageDeleteForm(QtGui.QDialog, Ui_SongUsageDeleteDialog):
|
||||||
self.button_box.clicked.connect(self.on_button_box_clicked)
|
self.button_box.clicked.connect(self.on_button_box_clicked)
|
||||||
|
|
||||||
def on_button_box_clicked(self, button):
|
def on_button_box_clicked(self, button):
|
||||||
|
"""
|
||||||
|
The button event has been triggered
|
||||||
|
|
||||||
|
:param button: The button pressed
|
||||||
|
"""
|
||||||
if self.button_box.standardButton(button) == QtGui.QDialogButtonBox.Ok:
|
if self.button_box.standardButton(button) == QtGui.QDialogButtonBox.Ok:
|
||||||
ret = QtGui.QMessageBox.question(self,
|
ret = QtGui.QMessageBox.question(
|
||||||
|
self,
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Selected Song Usage Events?'),
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Selected Song Usage Events?'),
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm',
|
translate('SongUsagePlugin.SongUsageDeleteForm',
|
||||||
'Are you sure you want to delete selected Song Usage data?'),
|
'Are you sure you want to delete selected Song Usage data?'),
|
||||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No)
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No)
|
||||||
if ret == QtGui.QMessageBox.Yes:
|
if ret == QtGui.QMessageBox.Yes:
|
||||||
delete_date = self.delete_calendar.selectedDate().toPyDate()
|
delete_date = self.delete_calendar.selectedDate().toPyDate()
|
||||||
self.manager.delete_all_objects(SongUsageItem, SongUsageItem.usagedate <= delete_date)
|
self.manager.delete_all_objects(SongUsageItem, SongUsageItem.usagedate <= delete_date)
|
||||||
self.main_window.information_message(
|
self.main_window.information_message(
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Deletion Successful'),
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Deletion Successful'),
|
||||||
translate(
|
translate('SongUsagePlugin.SongUsageDeleteForm',
|
||||||
'SongUsagePlugin.SongUsageDeleteForm', 'All requested data has been deleted successfully.')
|
'All requested data has been deleted successfully.')
|
||||||
)
|
)
|
||||||
self.accept()
|
self.accept()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -35,7 +35,15 @@ from openlp.core.lib.ui import create_button_box
|
||||||
|
|
||||||
|
|
||||||
class Ui_SongUsageDetailDialog(object):
|
class Ui_SongUsageDetailDialog(object):
|
||||||
|
"""
|
||||||
|
The Song Usage report details
|
||||||
|
"""
|
||||||
def setupUi(self, song_usage_detail_dialog):
|
def setupUi(self, song_usage_detail_dialog):
|
||||||
|
"""
|
||||||
|
Set up the UI
|
||||||
|
|
||||||
|
:param song_usage_detail_dialog:
|
||||||
|
"""
|
||||||
song_usage_detail_dialog.setObjectName('song_usage_detail_dialog')
|
song_usage_detail_dialog.setObjectName('song_usage_detail_dialog')
|
||||||
song_usage_detail_dialog.resize(609, 413)
|
song_usage_detail_dialog.resize(609, 413)
|
||||||
self.vertical_layout = QtGui.QVBoxLayout(song_usage_detail_dialog)
|
self.vertical_layout = QtGui.QVBoxLayout(song_usage_detail_dialog)
|
||||||
|
@ -82,6 +90,11 @@ class Ui_SongUsageDetailDialog(object):
|
||||||
self.save_file_push_button.clicked.connect(song_usage_detail_dialog.define_output_location)
|
self.save_file_push_button.clicked.connect(song_usage_detail_dialog.define_output_location)
|
||||||
|
|
||||||
def retranslateUi(self, song_usage_detail_dialog):
|
def retranslateUi(self, song_usage_detail_dialog):
|
||||||
|
"""
|
||||||
|
Retranslate the UI
|
||||||
|
|
||||||
|
:param song_usage_detail_dialog:
|
||||||
|
"""
|
||||||
song_usage_detail_dialog.setWindowTitle(
|
song_usage_detail_dialog.setWindowTitle(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Song Usage Extraction'))
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Song Usage Extraction'))
|
||||||
self.date_range_group_box.setTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Select Date Range'))
|
self.date_range_group_box.setTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Select Date Range'))
|
||||||
|
|
|
@ -66,8 +66,8 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
||||||
"""
|
"""
|
||||||
Triggered when the Directory selection button is clicked
|
Triggered when the Directory selection button is clicked
|
||||||
"""
|
"""
|
||||||
path = QtGui.QFileDialog.getExistingDirectory(self,
|
path = QtGui.QFileDialog.getExistingDirectory(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Output File Location'),
|
self, translate('SongUsagePlugin.SongUsageDetailForm', 'Output File Location'),
|
||||||
Settings().value(self.plugin.settings_section + '/last directory export'))
|
Settings().value(self.plugin.settings_section + '/last directory export'))
|
||||||
if path:
|
if path:
|
||||||
Settings().setValue(self.plugin.settings_section + '/last directory export', path)
|
Settings().setValue(self.plugin.settings_section + '/last directory export', path)
|
||||||
|
@ -83,7 +83,7 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
||||||
self.main_window.error_message(
|
self.main_window.error_message(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Output Path Not Selected'),
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Output Path Not Selected'),
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'You have not set a valid output location for your'
|
translate('SongUsagePlugin.SongUsageDetailForm', 'You have not set a valid output location for your'
|
||||||
' song usage report. Please select an existing path on your computer.')
|
' song usage report. \nPlease select an existing path on your computer.')
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
check_directory_exists(path)
|
check_directory_exists(path)
|
||||||
|
@ -109,8 +109,8 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
||||||
file_handle.write(record.encode('utf-8'))
|
file_handle.write(record.encode('utf-8'))
|
||||||
self.main_window.information_message(
|
self.main_window.information_message(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation'),
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation'),
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Report \n%s \n'
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'has been successfully created. ') % report_file_name
|
'Report \n%s \nhas been successfully created. ') % report_file_name
|
||||||
)
|
)
|
||||||
except IOError:
|
except IOError:
|
||||||
log.exception('Failed to write out song usage records')
|
log.exception('Failed to write out song usage records')
|
||||||
|
|
|
@ -48,21 +48,20 @@ def init_schema(url):
|
||||||
"""
|
"""
|
||||||
Setup the songusage database connection and initialise the database schema
|
Setup the songusage database connection and initialise the database schema
|
||||||
|
|
||||||
``url``
|
:param url: The database to setup
|
||||||
The database to setup
|
|
||||||
"""
|
"""
|
||||||
session, metadata = init_db(url)
|
session, metadata = init_db(url)
|
||||||
|
|
||||||
songusage_table = Table('songusage_data', metadata,
|
songusage_table = Table('songusage_data', metadata,
|
||||||
Column('id', types.Integer(), primary_key=True),
|
Column('id', types.Integer(), primary_key=True),
|
||||||
Column('usagedate', types.Date, index=True, nullable=False),
|
Column('usagedate', types.Date, index=True, nullable=False),
|
||||||
Column('usagetime', types.Time, index=True, nullable=False),
|
Column('usagetime', types.Time, index=True, nullable=False),
|
||||||
Column('title', types.Unicode(255), nullable=False),
|
Column('title', types.Unicode(255), nullable=False),
|
||||||
Column('authors', types.Unicode(255), nullable=False),
|
Column('authors', types.Unicode(255), nullable=False),
|
||||||
Column('copyright', types.Unicode(255)),
|
Column('copyright', types.Unicode(255)),
|
||||||
Column('ccl_number', types.Unicode(65)),
|
Column('ccl_number', types.Unicode(65)),
|
||||||
Column('plugin_name', types.Unicode(20)),
|
Column('plugin_name', types.Unicode(20)),
|
||||||
Column('source', types.Unicode(10))
|
Column('source', types.Unicode(10))
|
||||||
)
|
)
|
||||||
|
|
||||||
mapper(SongUsageItem, songusage_table)
|
mapper(SongUsageItem, songusage_table)
|
||||||
|
|
|
@ -58,6 +58,9 @@ __default_settings__ = {
|
||||||
|
|
||||||
|
|
||||||
class SongUsagePlugin(Plugin):
|
class SongUsagePlugin(Plugin):
|
||||||
|
"""
|
||||||
|
Song Usage Plugin class
|
||||||
|
"""
|
||||||
log.info('SongUsage Plugin loaded')
|
log.info('SongUsage Plugin loaded')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -79,31 +82,33 @@ class SongUsagePlugin(Plugin):
|
||||||
"""
|
"""
|
||||||
Give the SongUsage plugin the opportunity to add items to the **Tools** menu.
|
Give the SongUsage plugin the opportunity to add items to the **Tools** menu.
|
||||||
|
|
||||||
``tools_menu``
|
:param tools_menu: The actual **Tools** menu item, so that your actions can use it as their parent.
|
||||||
The actual **Tools** menu item, so that your actions can use it as their parent.
|
|
||||||
"""
|
"""
|
||||||
log.info('add tools menu')
|
log.info('add tools menu')
|
||||||
self.toolsMenu = tools_menu
|
self.tools_menu = tools_menu
|
||||||
self.song_usage_menu = QtGui.QMenu(tools_menu)
|
self.song_usage_menu = QtGui.QMenu(tools_menu)
|
||||||
self.song_usage_menu.setObjectName('song_usage_menu')
|
self.song_usage_menu.setObjectName('song_usage_menu')
|
||||||
self.song_usage_menu.setTitle(translate('SongUsagePlugin', '&Song Usage Tracking'))
|
self.song_usage_menu.setTitle(translate('SongUsagePlugin', '&Song Usage Tracking'))
|
||||||
# SongUsage Delete
|
# SongUsage Delete
|
||||||
self.song_usage_delete = create_action(tools_menu, 'songUsageDelete',
|
self.song_usage_delete = create_action(
|
||||||
|
tools_menu, 'songUsageDelete',
|
||||||
text=translate('SongUsagePlugin', '&Delete Tracking Data'),
|
text=translate('SongUsagePlugin', '&Delete Tracking Data'),
|
||||||
statustip=translate('SongUsagePlugin', 'Delete song usage data up to a specified date.'),
|
statustip=translate('SongUsagePlugin', 'Delete song usage data up to a specified date.'),
|
||||||
triggers=self.on_song_usage_delete)
|
triggers=self.on_song_usage_delete)
|
||||||
# SongUsage Report
|
# SongUsage Report
|
||||||
self.song_usage_report = create_action(tools_menu, 'songUsageReport',
|
self.song_usage_report = create_action(
|
||||||
|
tools_menu, 'songUsageReport',
|
||||||
text=translate('SongUsagePlugin', '&Extract Tracking Data'),
|
text=translate('SongUsagePlugin', '&Extract Tracking Data'),
|
||||||
statustip=translate('SongUsagePlugin', 'Generate a report on song usage.'),
|
statustip=translate('SongUsagePlugin', 'Generate a report on song usage.'),
|
||||||
triggers=self.on_song_usage_report)
|
triggers=self.on_song_usage_report)
|
||||||
# SongUsage activation
|
# SongUsage activation
|
||||||
self.song_usage_status = create_action(tools_menu, 'songUsageStatus',
|
self.song_usage_status = create_action(
|
||||||
|
tools_menu, 'songUsageStatus',
|
||||||
text=translate('SongUsagePlugin', 'Toggle Tracking'),
|
text=translate('SongUsagePlugin', 'Toggle Tracking'),
|
||||||
statustip=translate('SongUsagePlugin', 'Toggle the tracking of song usage.'), checked=False,
|
statustip=translate('SongUsagePlugin', 'Toggle the tracking of song usage.'), checked=False,
|
||||||
can_shortcuts=True, triggers=self.toggle_song_usage_state)
|
can_shortcuts=True, triggers=self.toggle_song_usage_state)
|
||||||
# Add Menus together
|
# Add Menus together
|
||||||
self.toolsMenu.addAction(self.song_usage_menu.menuAction())
|
self.tools_menu.addAction(self.song_usage_menu.menuAction())
|
||||||
self.song_usage_menu.addAction(self.song_usage_status)
|
self.song_usage_menu.addAction(self.song_usage_status)
|
||||||
self.song_usage_menu.addSeparator()
|
self.song_usage_menu.addSeparator()
|
||||||
self.song_usage_menu.addAction(self.song_usage_report)
|
self.song_usage_menu.addAction(self.song_usage_report)
|
||||||
|
@ -117,7 +122,7 @@ class SongUsagePlugin(Plugin):
|
||||||
self.song_usage_active_button.hide()
|
self.song_usage_active_button.hide()
|
||||||
# Signals and slots
|
# Signals and slots
|
||||||
QtCore.QObject.connect(self.song_usage_status, QtCore.SIGNAL('visibilityChanged(bool)'),
|
QtCore.QObject.connect(self.song_usage_status, QtCore.SIGNAL('visibilityChanged(bool)'),
|
||||||
self.song_usage_status.setChecked)
|
self.song_usage_status.setChecked)
|
||||||
self.song_usage_active_button.toggled.connect(self.toggle_song_usage_state)
|
self.song_usage_active_button.toggled.connect(self.toggle_song_usage_state)
|
||||||
self.song_usage_menu.menuAction().setVisible(False)
|
self.song_usage_menu.menuAction().setVisible(False)
|
||||||
|
|
||||||
|
@ -165,8 +170,7 @@ class SongUsagePlugin(Plugin):
|
||||||
|
|
||||||
def set_button_state(self):
|
def set_button_state(self):
|
||||||
"""
|
"""
|
||||||
Keep buttons inline. Turn of signals to stop dead loop but we need the
|
Keep buttons inline. Turn of signals to stop dead loop but we need the button and check box set correctly.
|
||||||
button and check box set correctly.
|
|
||||||
"""
|
"""
|
||||||
self.song_usage_active_button.blockSignals(True)
|
self.song_usage_active_button.blockSignals(True)
|
||||||
self.song_usage_status.blockSignals(True)
|
self.song_usage_status.blockSignals(True)
|
||||||
|
@ -186,12 +190,16 @@ class SongUsagePlugin(Plugin):
|
||||||
def display_song_usage(self, item):
|
def display_song_usage(self, item):
|
||||||
"""
|
"""
|
||||||
Song Usage for which has been displayed
|
Song Usage for which has been displayed
|
||||||
|
|
||||||
|
:param item: Item displayed
|
||||||
"""
|
"""
|
||||||
self._add_song_usage(translate('SongUsagePlugin', 'display'), item)
|
self._add_song_usage(translate('SongUsagePlugin', 'display'), item)
|
||||||
|
|
||||||
def print_song_usage(self, item):
|
def print_song_usage(self, item):
|
||||||
"""
|
"""
|
||||||
Song Usage for which has been printed
|
Song Usage for which has been printed
|
||||||
|
|
||||||
|
:param item: Item printed
|
||||||
"""
|
"""
|
||||||
self._add_song_usage(translate('SongUsagePlugin', 'printed'), item)
|
self._add_song_usage(translate('SongUsagePlugin', 'printed'), item)
|
||||||
|
|
||||||
|
@ -210,15 +218,28 @@ class SongUsagePlugin(Plugin):
|
||||||
self.manager.save_object(song_usage_item)
|
self.manager.save_object(song_usage_item)
|
||||||
|
|
||||||
def on_song_usage_delete(self):
|
def on_song_usage_delete(self):
|
||||||
|
"""
|
||||||
|
Request the delete form to be displayed
|
||||||
|
"""
|
||||||
self.song_usage_delete_form.exec_()
|
self.song_usage_delete_form.exec_()
|
||||||
|
|
||||||
def on_song_usage_report(self):
|
def on_song_usage_report(self):
|
||||||
|
"""
|
||||||
|
Display the song usage report generator screen
|
||||||
|
|
||||||
|
"""
|
||||||
self.song_usage_detail_form.initialise()
|
self.song_usage_detail_form.initialise()
|
||||||
self.song_usage_detail_form.exec_()
|
self.song_usage_detail_form.exec_()
|
||||||
|
|
||||||
def about(self):
|
def about(self):
|
||||||
|
"""
|
||||||
|
The plugin about text
|
||||||
|
|
||||||
|
:return: the text to be displayed
|
||||||
|
"""
|
||||||
about_text = translate('SongUsagePlugin',
|
about_text = translate('SongUsagePlugin',
|
||||||
'<strong>SongUsage Plugin</strong><br />This plugin tracks the usage of songs in services.')
|
'<strong>SongUsage Plugin</strong><br />'
|
||||||
|
'This plugin tracks the usage of songs in services.')
|
||||||
return about_text
|
return about_text
|
||||||
|
|
||||||
def set_plugin_text_strings(self):
|
def set_plugin_text_strings(self):
|
||||||
|
|
Loading…
Reference in New Issue