From ffa4ac4eeb519b4415769b42c05cbeaf5ebb1d7c Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Tue, 5 Feb 2013 18:07:37 +0000 Subject: [PATCH] 0003968: [NarWeb] Save/Restore settings for Narrated Website Generation. Change report_options file to be in the database directory, and implement different default report file and directory names based on the Family Tree Name. N.B. On upgrading, if you want to preserve your report_options, copy the report_option.xml file from the .gramps directory to the applicable .gramps.grampsdb. directory. Also don't forget that the default options are to EXCLUDE private and living data. svn: r21306 --- gramps/gen/plug/report/_options.py | 10 +++++++--- gramps/gui/plug/report/_docreportdialog.py | 8 ++++---- gramps/gui/plug/report/_graphvizreportdialog.py | 8 ++++---- gramps/plugins/webreport/narrativeweb.py | 14 ++++++++++---- gramps/plugins/webreport/webcal.py | 16 +++++++++++++--- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/gramps/gen/plug/report/_options.py b/gramps/gen/plug/report/_options.py index 7f13996f0..e64d67743 100644 --- a/gramps/gen/plug/report/_options.py +++ b/gramps/gen/plug/report/_options.py @@ -601,13 +601,14 @@ class OptionHandler(_options.OptionHandler): """ Implements handling of the options for the plugins. """ - def __init__(self, module_name, options_dict): + def __init__(self, module_name, options_dict, filename): + self.default_filename = filename _options.OptionHandler.__init__(self, module_name, options_dict, None) def init_subclass(self): self.collection_class = OptionListCollection self.list_class = OptionList - self.filename = REPORT_OPTIONS + self.filename = self.default_filename def init_common(self): """ @@ -777,9 +778,12 @@ class ReportOptions(_options.Options): self.options_dict = {} self.options_help = {} self.handler = None + self.default_report_options_file = os.path.join(dbase.full_name, + "report_options.xml") def load_previous_values(self): - self.handler = OptionHandler(self.name, self.options_dict) + self.handler = OptionHandler(self.name, self.options_dict, + self.default_report_options_file) def make_default_style(self, default_style): """ diff --git a/gramps/gui/plug/report/_docreportdialog.py b/gramps/gui/plug/report/_docreportdialog.py index fe3923e8a..84731f850 100644 --- a/gramps/gui/plug/report/_docreportdialog.py +++ b/gramps/gui/plug/report/_docreportdialog.py @@ -67,6 +67,7 @@ class DocReportDialog(ReportDialog): self.style_name = "default" self.firstpage_added = False self.CSS = PLUGMAN.process_plugin_data('WEBSTUFF') + self.dbname = dbstate.db.get_dbname() ReportDialog.__init__(self, dbstate, uistate, option_class, name, trans_name) @@ -184,10 +185,9 @@ class DocReportDialog(ReportDialog): ext = "" else: spath = self.get_default_directory() - if self.options.get_output(): - base = os.path.basename(self.options.get_output()) - else: - base = "%s.%s" % (self.report_name, ext) + default_name = self.dbname + "_" + \ + "".join(x[0].upper() for x in self.raw_name.split("_")) + base = "%s.%s" % (default_name, ext) spath = os.path.normpath(os.path.join(spath, base)) self.target_fileentry.set_filename(spath) diff --git a/gramps/gui/plug/report/_graphvizreportdialog.py b/gramps/gui/plug/report/_graphvizreportdialog.py index 41759042c..d968fd8c8 100644 --- a/gramps/gui/plug/report/_graphvizreportdialog.py +++ b/gramps/gui/plug/report/_graphvizreportdialog.py @@ -116,6 +116,7 @@ class GraphvizReportDialog(ReportDialog): more information.""" self.category = CATEGORY_GRAPHVIZ self.__gvoptions = graphdoc.GVOptions() + self.dbname = dbstate.db.get_dbname() ReportDialog.__init__(self, dbstate, uistate, opt, name, translated_name) @@ -165,10 +166,9 @@ class GraphvizReportDialog(ReportDialog): ext = "" else: spath = self.get_default_directory() - if self.options.get_output(): - base = os.path.basename(self.options.get_output()) - else: - base = "%s%s" % (self.report_name, ext) + default_name = self.dbname + "_" + \ + "".join(x[0].upper() for x in self.raw_name.split("_")) + base = "%s%s" % (default_name, ext) spath = os.path.normpath(os.path.join(spath, base)) self.target_fileentry.set_filename(spath) diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index 098f91cda..2948f8579 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -111,7 +111,7 @@ from gramps.gen.lib import (ChildRefType, Date, EventType, FamilyRelType, Name, EventRoleType, Family, Event, Place, Source, Citation, MediaObject, Repository, Note, Tag) from gramps.gen.lib.date import Today -from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION +from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, VERSION from gramps.gen.sort import Sort from gramps.gen.plug.menu import PersonOption, NumberOption, StringOption, \ BooleanOption, EnumeratedListOption, FilterOption, \ @@ -126,6 +126,7 @@ from gramps.gen.utils.file import media_path_full from gramps.gen.utils.alive import probably_alive from gramps.gen.utils.db import get_source_and_citation_referents from gramps.gen.constfunc import win, cuni, conv_to_unicode, UNITYPE +from gramps.gen.config import config from gramps.gui.thumbnails import get_thumbnail_path, run_thumbnailer from gramps.gen.utils.image import image_size, resize_to_jpeg_buffer from gramps.gen.mime import get_description @@ -6988,6 +6989,8 @@ class NavWebReport(Report): self.user.notify_error(_("Could not create %s") % self.target_path, str(value)) return + config.set('paths.website-directory', + os.path.dirname(self.target_path) + os.sep) # for use with discovering biological, half, and step siblings for use # in display_ind_parents()... @@ -7974,8 +7977,11 @@ class NavWebOptions(MenuReportOptions): addopt( "archive", self.__archive ) self.__archive.connect('value-changed', self.__archive_changed) + dbname = self.__db.get_dbname() + default_dir = dbname + "_" + "NAVWEB" self.__target = DestinationOption(_("Destination"), - os.path.join(USER_HOME, "NAVWEB")) + os.path.join(config.get('paths.website-directory'), + default_dir)) self.__target.set_help( _("The destination directory for the web " "files")) addopt( "target", self.__target ) @@ -8196,7 +8202,7 @@ class NavWebOptions(MenuReportOptions): self.__incdownload.connect('value-changed', self.__download_changed) self.__down_fname1 = DestinationOption(_("Download Filename"), - os.path.join(USER_HOME, "")) + os.path.join(config.get('paths.website-directory'), "")) self.__down_fname1.set_help(_("File to be used for downloading of database")) addopt( "down_fname1", self.__down_fname1 ) @@ -8205,7 +8211,7 @@ class NavWebOptions(MenuReportOptions): addopt( "dl_descr1", self.__dl_descr1 ) self.__down_fname2 = DestinationOption(_("Download Filename"), - os.path.join(USER_HOME, "")) + os.path.join(config.get('paths.website-directory'), "")) self.__down_fname2.set_help(_("File to be used for downloading of database")) addopt( "down_fname2", self.__down_fname2 ) diff --git a/gramps/plugins/webreport/webcal.py b/gramps/plugins/webreport/webcal.py index e91ec0337..d9659e1cc 100644 --- a/gramps/plugins/webreport/webcal.py +++ b/gramps/plugins/webreport/webcal.py @@ -52,6 +52,7 @@ from gramps.gen.lib import Date, Name, NameType, Person from gramps.gen.lib.date import Today from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION from gramps.gen.constfunc import win +from gramps.gen.config import config from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions @@ -249,6 +250,8 @@ class WebCalReport(Report): "a different directory to store your generated " "web pages.")) self.warn_dir = False + config.set('paths.website-directory', + os.path.dirname(self.html_dir) + os.sep) def add_day_item(self, text, year, month, day, event): """ @@ -1301,8 +1304,11 @@ class WebCalOptions(MenuReportOptions): """ category_name = _("Report Options") + dbname = self.__db.get_dbname() + default_dir = dbname + "_WEBCAL" target = DestinationOption( _("Destination"), - os.path.join(USER_HOME, "WEBCAL")) + os.path.join(config.get('paths.website-directory'), + default_dir)) target.set_help( _("The destination directory for the web files")) target.set_directory_entry(True) menu.add_option(category_name, "target", target) @@ -1420,7 +1426,9 @@ class WebCalOptions(MenuReportOptions): start_dow.set_help(_("Select the first day of the week for the calendar")) menu.add_option(category_name, "start_dow", start_dow) - home_link = StringOption(_('Home link'), '../../NAVWEB/index.html') + dbname = self.__db.get_dbname() + default_link = '../../' + dbname + "_NAVWEB/index.html" + home_link = StringOption(_('Home link'), default_link) home_link.set_help(_("The link to be included to direct the user to " "the main page of the web site")) menu.add_option(category_name, "home_link", home_link) @@ -1521,7 +1529,9 @@ class WebCalOptions(MenuReportOptions): menu.add_option(category_name, 'link_to_narweb', self.__links) self.__links.connect('value-changed', self.__links_changed) - self.__prefix = StringOption(_('Link prefix'), "../../NAVWEB/") + dbname = self.__db.get_dbname() + default_prefix = '../../' + dbname + "_NAVWEB/" + self.__prefix = StringOption(_('Link prefix'), default_prefix) self.__prefix.set_help(_("A Prefix on the links to take you to " "Narrated Web Report")) menu.add_option(category_name, "prefix", self.__prefix)