From 167b009dcd282000a0a2bf1afaec36481c941690 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Wed, 31 Jan 2007 03:16:11 +0000 Subject: [PATCH] * src/plugins/IndivComplete.py: fix source citations (0000867) * src/ReportBase.py: fix source citations (0000867) svn: r8020 --- gramps2/ChangeLog | 2 + gramps2/src/ReportBase/_ReportUtils.py | 29 ++++++++++ gramps2/src/plugins/IndivComplete.py | 75 +++++++++++++------------- 3 files changed, 69 insertions(+), 37 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index d4ab8dde8..14d0335cb 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -5,6 +5,8 @@ * src/docgen/HtmlDoc.py: add start_superscript and stop_superscript * src/docgen/OpenOfficeDoc.py: add start_superscript and stop_superscript * src/docgen/LaTeXDoc.py: add start_superscript and stop_superscript + * src/plugins/IndivComplete.py: fix source citations (0000867) + * src/ReportBase.py: fix source citations (0000867) 2007-01-30 Don Allingham * src/plugins/EventCmp.py: (#886) properly handle CANCEL on save dialog diff --git a/gramps2/src/ReportBase/_ReportUtils.py b/gramps2/src/ReportBase/_ReportUtils.py index 36b467a6b..315b192db 100644 --- a/gramps2/src/ReportBase/_ReportUtils.py +++ b/gramps2/src/ReportBase/_ReportUtils.py @@ -33,6 +33,7 @@ A collection of utilities to aid in the generation of reports. import time import os from gettext import gettext as _ +import cStringIO #------------------------------------------------------------------------ # @@ -2314,3 +2315,31 @@ def get_address_str(addr): str = "%s, %s" % (str,info) return str +def get_endnotes(sref_map,obj): + if not obj: + return "" + + slist = obj.get_source_references() + + if not slist: + return "" + + msg = cStringIO.StringIO() + first = 1 + for ref in slist: + if not first: + msg.write(',') + first = 0 + ref_base = ref.get_reference_handle() + the_key = 0 + for key in sref_map.keys(): + if ref_base == sref_map[key].get_reference_handle(): + the_key = key + break + if not the_key: + the_key = len(sref_map) + 1 + sref_map[the_key] = ref + msg.write("%d" % the_key) + str = msg.getvalue() + msg.close() + return str \ No newline at end of file diff --git a/gramps2/src/plugins/IndivComplete.py b/gramps2/src/plugins/IndivComplete.py index cf453708f..443de885a 100644 --- a/gramps2/src/plugins/IndivComplete.py +++ b/gramps2/src/plugins/IndivComplete.py @@ -85,6 +85,7 @@ class IndivCompleteReport(Report): filter_num = options_class.get_filter_number() filters = options_class.get_report_filters(person) self.filter = filters[filter_num] + self.sref_map = {} def define_table_styles(self): tbl = BaseDoc.TableStyle() @@ -137,19 +138,19 @@ class IndivCompleteReport(Report): description = event.get_description() text = '%s%s. ' % (text,description) - + endnotes = "" if self.use_srcs: - for s in event.get_source_references(): - src_handle = s.get_reference_handle() - src = self.database.get_source_from_handle(src_handle) - text = "%s [%s]" % (text,src.get_gramps_id()) - self.slist.append(s) + endnotes = ReportUtils.get_endnotes(self.sref_map,event) self.doc.start_row() self.normal_cell(name) self.doc.start_cell('IDS-NormalCell') self.doc.start_paragraph('IDS-Normal') self.doc.write_text(text) + if endnotes: + self.doc.start_superscript() + self.doc.write_text(endnotes) + self.doc.end_superscript() self.doc.end_paragraph() note = event.get_note() @@ -268,13 +269,10 @@ class IndivCompleteReport(Report): self.doc.start_row() self.normal_cell(name_type) text = _nd.display_name(name) + endnotes = "" if self.use_srcs: - for s in name.get_source_references(): - src_handle = s.get_reference_handle() - src = self.database.get_source_from_handle(src_handle) - text = "%s [%s]" % (text,src.get_gramps_id()) - self.slist.append(s) - self.normal_cell(text) + endnotes = ReportUtils.get_endnotes(self.sref_map,name) + self.normal_cell(text,endnotes) self.doc.end_row() self.doc.end_table() self.doc.start_paragraph('IDS-Normal') @@ -299,16 +297,12 @@ class IndivCompleteReport(Report): for addr in alist: text = ReportUtils.get_address_str(addr) date = DateHandler.get_date(addr) - + endnotes = "" + if self.use_srcs: + endnotes = ReportUtils.get_endnotes(self.sref_map,addr) self.doc.start_row() self.normal_cell(date) - if self.use_srcs: - for s in addr.get_source_references(): - src_handle = s.get_reference_handle() - src = self.database.get_source_from_handle(src_handle) - text = "%s [%s]" % (text,src.get_gramps_id()) - self.slist.append(s) - self.normal_cell(text) + self.normal_cell(text,endnotes) self.doc.end_row() self.doc.end_table() self.doc.start_paragraph('IDS-Normal') @@ -375,8 +369,8 @@ class IndivCompleteReport(Report): self.doc.end_paragraph() def write_sources(self): - - if len(self.slist) == 0: + keys = self.sref_map.keys() + if not keys: return self.doc.start_table("three","IDS-IndTable") @@ -387,14 +381,20 @@ class IndivCompleteReport(Report): self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() - - for source in self.slist: + + keys.sort() + for key in keys: + srcref = self.sref_map[key] + base = self.database.get_source_from_handle( + srcref.get_reference_handle()) self.doc.start_row() - s_handle = source.get_reference_handle() - src = self.database.get_source_from_handle(s_handle) - self.normal_cell(src.get_gramps_id()) - self.normal_cell(src.get_title()) + self.doc.start_cell('IDS-NormalCell',2) + self.doc.start_paragraph("IDS-Normal","%d." % key) + self.doc.write_text(base.get_title()) + self.doc.end_paragraph() + self.doc.end_cell() self.doc.end_row() + self.doc.end_table() def write_facts(self): @@ -416,10 +416,14 @@ class IndivCompleteReport(Report): self.doc.start_paragraph("IDS-Normal") self.doc.end_paragraph() - def normal_cell(self,text,mark=None): + def normal_cell(self,text,endnotes=None,mark=None): self.doc.start_cell('IDS-NormalCell') self.doc.start_paragraph('IDS-Normal') self.doc.write_text(text,mark) + if endnotes: + self.doc.start_superscript() + self.doc.write_text(endnotes) + self.doc.end_superscript() self.doc.end_paragraph() self.doc.end_cell() @@ -474,13 +478,10 @@ class IndivCompleteReport(Report): name = self.start_person.get_primary_name() text = _nd.display_name(name) mark = ReportUtils.get_person_mark(self.database, self.start_person) + endnotes = "" if self.use_srcs: - for s in name.get_source_references(): - self.slist.append(s) - src_handle = s.get_reference_handle() - src = self.database.get_source_from_handle(src_handle) - text = "%s [%s]" % (text,src.get_gramps_id()) - self.normal_cell(text,mark) + endnotes = ReportUtils.get_endnotes(self.sref_map,name) + self.normal_cell(text,endnotes,mark) self.doc.end_row() self.doc.start_row() @@ -520,12 +521,12 @@ class IndivCompleteReport(Report): self.doc.start_row() self.normal_cell("%s:" % _("Father")) - self.normal_cell(father,fmark) + self.normal_cell(father,mark=fmark) self.doc.end_row() self.doc.start_row() self.normal_cell("%s:" % _("Mother")) - self.normal_cell(mother,mmark) + self.normal_cell(mother,mark=mmark) self.doc.end_row() self.doc.end_table()