From 77cfc58259d19fd18d14c43a355918b98a21283b Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Mon, 12 Nov 2012 18:40:10 +0000 Subject: [PATCH] Tidy up sources pages - fix numbering of repositories, remove unused parameters, fix title of individual source pages svn: r20654 --- gramps/plugins/webreport/narrativeweb.py | 82 ++++++++++++++++-------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index 5afb3e21d..da2e295e5 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -2677,7 +2677,8 @@ class BasePage(object): """ dumps the repository """ - + if len(repo_ref_list) == 0: + return None # Repository list division... with Html("div", class_ ="subsection", id ="repositories") as repositories: repositories += Html("h4", _("Repositories"), inline = True) @@ -2708,6 +2709,7 @@ class BasePage(object): repository.get_gramps_id(), self.up)) ) tbody += trow + index += 1 return repositories def dump_residence(self, has_res): @@ -4281,12 +4283,24 @@ class SourcePages(BasePage): repo_handle, source_fname, source_name, source.gramps_id) - def display_pages(self, report, title, source_list, ppl_handle_list, - database_handles_list): - # FIXME: Most of the parameters should be removed. report is passed to - # __init__, title appears not to be used and source_list, - # ppl_handle_list and database_handles_list violate modularity and - # should be removed. + def display_pages(self, report, title, source_list): + """ + Generate and output the pages under the Sources tab, namely the sources + index and the individual sources pages. + + @param: report -- the instance of the main report class for this report + @param: title -- the web site title + @param: source_list -- a dictionary object containg source handles as + the key and (backlink filename, backlink page_title, backlink gid) as + values -- now replaced by self.source_dict + + @param: ppl_handle_list -- list of Person handles that are included in + the web site -- no longer used + @param: database_handles_list -- tuple containg lists of persons, + families, events, places repositories and media that are included in + the web site -- no longer used + """ + # FIXME: Perhaps report and title should just be passed in to the class log.debug("source_dict") for item in self.source_dict.iteritems(): log.debug(" %s" % str(item)) @@ -4298,23 +4312,29 @@ class SourcePages(BasePage): log.debug("\n") report.user.begin_progress(_("Narrated Web Site Report"), _("Creating source pages"), - len(source_list) + 1) - self.SourceListPage(report, title, list(source_list.keys())) + len(source_dict) + 1) + self.SourceListPage(report, title, list(source_dict.keys())) for item in self.source_dict.iteritems(): report.user.step_progress() - self.SourcePage(report, title, source_handle, source_list, - ppl_handle_list, database_handles_list) + self.SourcePage(report, title, item) report.user.end_progress() pass - def SourceListPage(self, report, title, handle_set): + def SourceListPage(self, report, title, source_handles): + """ + Generate and output the Sources index page. + + @param: report -- the instance of the main report class for this report + @param: title -- the web site title + @param: source_handles -- a list of the handles of the sources to be + displayed + """ self.dbase_ = report.database BasePage.__init__(self, report, title) - handle_list = list(handle_set) source_dict = {} of, sio = self.report.create_file("sources") @@ -4325,8 +4345,8 @@ class SourcePages(BasePage): body += sourceslist # Sort the sources - for handle in handle_list: - source = self.dbase_.get_source_from_handle(handle) + for handle in source_handles: + source = self.db.get_source_from_handle(handle) if source is not None: key = source.get_title() + str(source.get_gramps_id()) source_dict[key] = (source, handle) @@ -4334,8 +4354,8 @@ class SourcePages(BasePage): keys = sorted(source_dict, key=locale.strxfrm) msg = _("This page contains an index of all the sources in the " - "database, sorted by their title. Clicking on a source’s " - "title will take you to that source’s page.") + "database, sorted by their title. Clicking on a source’s " + "title will take you to that source’s page.") sourceslist += Html("p", msg, id = "description") # begin sourcelist table and table head @@ -4380,17 +4400,24 @@ class SourcePages(BasePage): # and close the file self.XHTMLWriter(sourcelistpage, of, sio) - def SourcePage(self, report, title, item, src_handle, src_list, ind_list, - database_handles_list): - self.dbase_ = report.database + def SourcePage(self, report, title, item): + """ + Generate and output an individual Source page. + + @param: report -- the instance of the main report class for this report + @param: title -- the web site title + @param: item -- a tuple containing the source handle and a list of + back-references + """ + self.dbase_ = report.database # needed for dump_repository_ref_list (src_handle, bkref_list) = item - source = self.dbase_.get_source_from_handle(src_handle) + source = self.db.get_source_from_handle(src_handle) if not source: return - self.page_title = source.get_title() BasePage.__init__(self, report, title, source.get_gramps_id()) + self.page_title = source.get_title() inc_repositories = self.report.options["inc_repository"] self.navigation = self.report.options['navigation'] @@ -4398,7 +4425,8 @@ class SourcePages(BasePage): of, sio = self.report.create_file(src_handle, "src") self.up = True - sourcepage, head, body = self.write_header(_('Sources')) + sourcepage, head, body = self.write_header("%s - %s" % (_('Sources'), + self.page_title)) # begin source detail division with Html("div", class_ = "content", id = "SourceDetail") as sourcedetail: @@ -7576,9 +7604,7 @@ class NavWebReport(Report): # build classes SourceListPage and SourcePage # has been moved so that all Sources can be found before processing... - self.tab["Source"].display_pages(self, self.title, source_list, - ind_list, database_handles_list) - self.source_pages(source_list, ind_list, database_handles_list) + self.tab["Source"].display_pages(self, self.title, source_list) # if an archive is being used, close it? if self.archive: @@ -8825,8 +8851,8 @@ def first_letter(string): second_letter = normalize('NFKC', cuni(string))[1].upper() if second_letter == cuni('Z'): letter += cuni('z') - elif second_letter == cuni('≈Ω'): - letter += cuni('≈æ') + elif second_letter == cuni('‚âàŒ©'): + letter += cuni('‚âà√¶') return letter def get_first_letters(dbase, menu_set, key):