forked from openlp/openlp
SongUsage cleanup
This commit is contained in:
parent
ab092e0124
commit
139cf93541
@ -315,7 +315,7 @@ def check_directory_exists(dir):
|
|||||||
``dir``
|
``dir``
|
||||||
Theme directory to make sure exists
|
Theme directory to make sure exists
|
||||||
"""
|
"""
|
||||||
log.debug(u'check_directory_exists')
|
log.debug(u'check_directory_exists %s' % dir)
|
||||||
if not os.path.exists(dir):
|
if not os.path.exists(dir):
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
|
||||||
|
@ -60,10 +60,11 @@ class Ui_SongUsageDetailDialog(object):
|
|||||||
self.horizontalLayout.setObjectName(u'horizontalLayout')
|
self.horizontalLayout.setObjectName(u'horizontalLayout')
|
||||||
self.fileLineEdit = QtGui.QLineEdit(self.fileGroupBox)
|
self.fileLineEdit = QtGui.QLineEdit(self.fileGroupBox)
|
||||||
self.fileLineEdit.setObjectName(u'fileLineEdit')
|
self.fileLineEdit.setObjectName(u'fileLineEdit')
|
||||||
|
self.fileLineEdit.setReadOnly(True)
|
||||||
self.horizontalLayout.addWidget(self.fileLineEdit)
|
self.horizontalLayout.addWidget(self.fileLineEdit)
|
||||||
self.saveFilePushButton = QtGui.QPushButton(self.fileGroupBox)
|
self.saveFilePushButton = QtGui.QPushButton(self.fileGroupBox)
|
||||||
self.saveFilePushButton.setIcon(
|
self.saveFilePushButton.setIcon(
|
||||||
build_icon(u':/general/general_load.png'))
|
build_icon(u':/general/general_open.png'))
|
||||||
self.saveFilePushButton.setObjectName(u'saveFilePushButton')
|
self.saveFilePushButton.setObjectName(u'saveFilePushButton')
|
||||||
self.horizontalLayout.addWidget(self.saveFilePushButton)
|
self.horizontalLayout.addWidget(self.saveFilePushButton)
|
||||||
self.verticalLayout4.addLayout(self.horizontalLayout)
|
self.verticalLayout4.addLayout(self.horizontalLayout)
|
||||||
@ -96,4 +97,4 @@ class Ui_SongUsageDetailDialog(object):
|
|||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'to'))
|
translate('SongUsagePlugin.SongUsageDetailForm', 'to'))
|
||||||
self.fileGroupBox.setTitle(
|
self.fileGroupBox.setTitle(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm',
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'Report Location'))
|
'Report Location'))
|
||||||
|
@ -30,7 +30,7 @@ import os
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from sqlalchemy.sql import and_
|
from sqlalchemy.sql import and_
|
||||||
|
|
||||||
from openlp.core.lib import SettingsManager, translate
|
from openlp.core.lib import SettingsManager, translate, check_directory_exists
|
||||||
from openlp.plugins.songusage.lib.db import SongUsageItem
|
from openlp.plugins.songusage.lib.db import SongUsageItem
|
||||||
from songusagedetaildialog import Ui_SongUsageDetailDialog
|
from songusagedetaildialog import Ui_SongUsageDetailDialog
|
||||||
|
|
||||||
@ -51,49 +51,68 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
|||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
|
"""
|
||||||
|
We need to set up the screen
|
||||||
|
"""
|
||||||
year = QtCore.QDate().currentDate().year()
|
year = QtCore.QDate().currentDate().year()
|
||||||
if QtCore.QDate().currentDate().month() < 9:
|
if QtCore.QDate().currentDate().month() < 9:
|
||||||
year -= 1
|
year -= 1
|
||||||
toDate = QtCore.QDate(year, 8, 31)
|
toDate = QtCore.QSettings().value(
|
||||||
fromDate = QtCore.QDate(year - 1, 9, 1)
|
u'songusage/to date',
|
||||||
|
QtCore.QVariant(QtCore.QDate(year, 8, 31))).toDate()
|
||||||
|
fromDate = QtCore.QSettings().value(
|
||||||
|
u'songusage/from date',
|
||||||
|
QtCore.QVariant(QtCore.QDate(year - 1, 9, 1))).toDate()
|
||||||
self.fromDate.setSelectedDate(fromDate)
|
self.fromDate.setSelectedDate(fromDate)
|
||||||
self.toDate.setSelectedDate(toDate)
|
self.toDate.setSelectedDate(toDate)
|
||||||
self.fileLineEdit.setText(
|
self.fileLineEdit.setText(
|
||||||
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
||||||
|
|
||||||
def defineOutputLocation(self):
|
def defineOutputLocation(self):
|
||||||
|
"""
|
||||||
|
Triggered when the Directory selection button is pressed
|
||||||
|
"""
|
||||||
path = QtGui.QFileDialog.getExistingDirectory(self,
|
path = QtGui.QFileDialog.getExistingDirectory(self,
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm',
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'Output File Location'),
|
'Output File Location'),
|
||||||
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
||||||
path = unicode(path)
|
path = unicode(path)
|
||||||
if path != u'':
|
if path:
|
||||||
SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1)
|
SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1)
|
||||||
self.fileLineEdit.setText(path)
|
self.fileLineEdit.setText(path)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
log.debug(u'Detailed report generated')
|
"""
|
||||||
|
Ok was pressed so lets save the data and run the report
|
||||||
|
"""
|
||||||
|
log.debug(u'accept')
|
||||||
|
path = unicode(self.fileLineEdit.text())
|
||||||
|
check_directory_exists(path)
|
||||||
filename = unicode(translate('SongUsagePlugin.SongUsageDetailForm',
|
filename = unicode(translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'usage_detail_%s_%s.txt')) % (
|
'usage_detail_%s_%s.txt')) % (
|
||||||
self.fromDate.selectedDate().toString(u'ddMMyyyy'),
|
self.fromDate.selectedDate().toString(u'ddMMyyyy'),
|
||||||
self.toDate.selectedDate().toString(u'ddMMyyyy'))
|
self.toDate.selectedDate().toString(u'ddMMyyyy'))
|
||||||
|
QtCore.QSettings().setValue(u'songusage/from date',
|
||||||
|
QtCore.QVariant(self.fromDate.selectedDate()))
|
||||||
|
QtCore.QSettings().setValue(u'songusage/to date',
|
||||||
|
QtCore.QVariant(self.toDate.selectedDate()))
|
||||||
usage = self.plugin.manager.get_all_objects(
|
usage = self.plugin.manager.get_all_objects(
|
||||||
SongUsageItem, and_(
|
SongUsageItem, and_(
|
||||||
SongUsageItem.usagedate >= self.fromDate.selectedDate().toPyDate(),
|
SongUsageItem.usagedate >= self.fromDate.selectedDate().toPyDate(),
|
||||||
SongUsageItem.usagedate < self.toDate.selectedDate().toPyDate()),
|
SongUsageItem.usagedate < self.toDate.selectedDate().toPyDate()),
|
||||||
[SongUsageItem.usagedate, SongUsageItem.usagetime])
|
[SongUsageItem.usagedate, SongUsageItem.usagetime])
|
||||||
outname = os.path.join(unicode(self.fileLineEdit.text()), filename)
|
outname = os.path.join(path, filename)
|
||||||
file = None
|
fileHandle = None
|
||||||
try:
|
try:
|
||||||
file = open(outname, u'w')
|
fileHandle = open(outname, u'w')
|
||||||
for instance in usage:
|
for instance in usage:
|
||||||
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % (
|
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % (
|
||||||
instance.usagedate, instance.usagetime, instance.title,
|
instance.usagedate, instance.usagetime, instance.title,
|
||||||
instance.copyright, instance.ccl_number, instance.authors)
|
instance.copyright, instance.ccl_number, instance.authors)
|
||||||
file.write(record)
|
fileHandle.write(record.encode(u'utf-8'))
|
||||||
except IOError:
|
except IOError:
|
||||||
log.exception(u'Failed to write out song usage records')
|
log.exception(u'Failed to write out song usage records')
|
||||||
finally:
|
finally:
|
||||||
if file:
|
if fileHandle:
|
||||||
file.close()
|
fileHandle.close()
|
||||||
self.close()
|
self.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user