Updates to NarrativeWeb and _bibliography for citations.

svn: r18499
This commit is contained in:
Tim G L Lyons 2011-11-25 17:29:30 +00:00
parent 6cb761b010
commit 99d42f6091
2 changed files with 66 additions and 41 deletions

View File

@ -3,6 +3,7 @@
# #
# Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2007 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -71,7 +72,7 @@ class Citation(object):
add another one. add another one.
@param source_ref: Source Reference @param source_ref: Source Reference
@type source_ref: L{gen.lib.srcref} @type source_ref: L{gen.lib.citation}
@return: The key of the added reference among all the references. @return: The key of the added reference among all the references.
@rtype: char @rtype: char
""" """
@ -113,7 +114,7 @@ class Bibliography(object):
def __init__(self, mode=MODE_ALL): def __init__(self, mode=MODE_ALL):
""" """
A bibliography will store citations (sources) and references to those A bibliography will store citations (sources) and references to those
citations (source refs). Duplicate entries will not be added. To change citations (citations). Duplicate entries will not be added. To change
what is considered duplicate, you can tell the bibliography what source what is considered duplicate, you can tell the bibliography what source
ref information you are interested in by passing in the mode. ref information you are interested in by passing in the mode.
@ -131,20 +132,28 @@ class Bibliography(object):
self.__citation_list = [] self.__citation_list = []
self.mode = mode self.mode = mode
def add_reference(self, source_ref): def add_reference(self, lib_citation):
""" """
Add a reference to a source to this bibliography. If the source already Add a reference to a source to this bibliography. If the source already
exists, don't add it again. If a similar reference exists, don't exists, don't add it again. If a similar reference exists, don't
add another one. add another one.
@param source_ref: Source Reference @param citation: Citation object
@type source_ref: L{gen.lib.srcref} @type citation: L{gen.lib.Citation}
@return: A tuple containing the index of the source among all the @return: A tuple containing the index of the source among all the
sources and the key of the reference among all the references. If sources and the key of the reference among all the references. If
there is no reference information, the second element will be None. there is no reference information, the second element will be None.
@rtype: (int,char) or (int,None) @rtype: (int,char) or (int,None)
N.B. Within this file, the name 'citation' is used both for
gen.lib.Citation, and for _bibliography.Citation. It is not clear how
best to rename the concepts in this file to avoid the clash, so the
names have been retained. In this function, lib_citation is used for
gen.lib.Citation instances, and citation for _bibliography.Citation
instances. Elsewhere in this file, source_ref is used for
gen.lib.Citation instances.
""" """
source_handle = source_ref.get_reference_handle() source_handle = lib_citation.get_reference_handle()
cindex = 0 cindex = 0
rkey = "" rkey = ""
citation = None citation = None
@ -161,13 +170,13 @@ class Bibliography(object):
cindex = len(self.__citation_list) cindex = len(self.__citation_list)
self.__citation_list.append(citation) self.__citation_list.append(citation)
if self.__sref_has_info(source_ref): if self.__sref_has_info(lib_citation):
for key, ref in citation.get_ref_list(): for key, ref in citation.get_ref_list():
if self.__srefs_are_equal(ref, source_ref): if self.__srefs_are_equal(ref, lib_citation):
# if a reference like this already exists, don't add # if a reference like this already exists, don't add
# another one # another one
return (cindex, key) return (cindex, key)
rkey = citation.add_reference(source_ref) rkey = citation.add_reference(lib_citation)
return (cindex, rkey) return (cindex, rkey)
@ -216,8 +225,17 @@ class Bibliography(object):
Determine if two source references are equal based on the Determine if two source references are equal based on the
current mode. current mode.
""" """
# The criterion for equality (in mode==MODE_ALL) is changed for
# citations. Previously, it was based on is_equal from SecondaryObject,
# which does a 'cmp' on the serialised data. (Note that this might not
# have worked properly for Dates; see comments in Date.is_equal and
# EditCitation.data_has_changed). The comparison is now made as to
# whether the two gen.lib.Citations have the same handle (i.e. they are
# actually the same database objects). It is felt that this better
# reflects the intent of Citation objects, which can be merged if they
# are intended to represent the same citation.
if self.mode == self.MODE_ALL: if self.mode == self.MODE_ALL:
return source_ref1.is_equal(source_ref2) return source_ref1.handle == source_ref2.handle
if ( self.mode & self.MODE_PAGE ) == self.MODE_PAGE: if ( self.mode & self.MODE_PAGE ) == self.MODE_PAGE:
if source_ref1.get_page() != source_ref2.get_page(): if source_ref1.get_page() != source_ref2.get_page():
return False return False

View File

@ -13,6 +13,7 @@
# Copyright (C) 2010 Doug Blank <doug.blank@gmail.com> # Copyright (C) 2010 Doug Blank <doug.blank@gmail.com>
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2010 Serge Noiraud # Copyright (C) 2010 Serge Noiraud
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -423,38 +424,40 @@ class BasePage(object):
["Type", str(attr.get_type()) ], ["Type", str(attr.get_type()) ],
["Value", attr.get_value() ], ["Value", attr.get_value() ],
["Notes", self.dump_notes(attr.get_note_list()) ], ["Notes", self.dump_notes(attr.get_note_list()) ],
["Sources", self.get_citation_links(attr.get_source_references()) ] ] ["Sources", self.get_citation_links(attr.get_citation_list()) ] ]
) )
# return table row to its caller # return table row to its caller
return trow return trow
def get_citation_links(self, source_ref_list): def get_citation_links(self, citation_handle_list):
""" """
get citation link from the source reference list get citation link from the citation handle list
@param: source_ref_list = list of source references @param: citation_handle_list = list of gen/lib/Citation
""" """
gid_list = []
lnk = (self.report.cur_fname, self.page_title, self.gid) lnk = (self.report.cur_fname, self.page_title, self.gid)
for sref in source_ref_list:
handle = sref.get_reference_handle()
gid_list.append(sref)
if handle in self.src_list:
if lnk not in self.src_list[handle]:
self.src_list[handle].append(lnk)
else:
self.src_list[handle] = [lnk]
text = "" text = ""
if len(gid_list):
for ref in gid_list: for citation_handle in citation_handle_list:
index, key = self.bibli.add_reference(ref) citation = self.report.database.get_citation_from_handle(
id_ = "%d%s" % (index+1, key) citation_handle)
text += ' [<a href="#sref%s ">%s</a>]' % (id_, id_)
# Add the source information to src_list for use when displaying the
# Sources page
source_handle = citation.get_reference_handle()
if source_handle in self.src_list:
if lnk not in self.src_list[source_handle]:
self.src_list[source_handle].append(lnk)
else:
self.src_list[source_handle] = [lnk]
# Add the citation information to the bibliography, and construct
# the citation reference text
index, key = self.bibli.add_reference(citation)
id_ = "%d%s" % (index+1, key)
text += ' [<a href="#sref%s ">%s</a>]' % (id_, id_)
# return citation list text to its callers # return citation list text to its callers
return text return text
@ -633,7 +636,7 @@ class BasePage(object):
trow += Html("td", htmllist, class_ = "ColumnNotes") trow += Html("td", htmllist, class_ = "ColumnNotes")
# get event source references # get event source references
srcrefs = self.get_citation_links(event.get_source_references()) or "&nbsp;" srcrefs = self.get_citation_links(event.get_citation_list()) or "&nbsp;"
trow += Html("td", srcrefs, class_ = "ColumnSources") trow += Html("td", srcrefs, class_ = "ColumnSources")
# return events table row to its callers # return events table row to its callers
@ -823,7 +826,7 @@ class BasePage(object):
["LDSTemple", ord.get_temple()], ["LDSTemple", ord.get_temple()],
["LDSPlace", place_hyper], ["LDSPlace", place_hyper],
["LDSStatus", ord.get_status()], ["LDSStatus", ord.get_status()],
["LDSSources", self.get_citation_links(ord.get_source_references() )] ] ["LDSSources", self.get_citation_links(ord.get_citation_list() )] ]
) )
# return table to its callers # return table to its callers
@ -961,7 +964,7 @@ class BasePage(object):
# get source citation list # get source citation list
if showsrc in [True, None]: if showsrc in [True, None]:
addr_data_row.append(["Sources", self.get_citation_links( addr_data_row.append(["Sources", self.get_citation_links(
address.get_source_references() )]) address.get_citation_list() )])
trow.extend( trow.extend(
Html("td", value or "&nbsp;", class_="Column" + colclass, inline=True) Html("td", value or "&nbsp;", class_="Column" + colclass, inline=True)
@ -1756,7 +1759,9 @@ class BasePage(object):
will create the "Source References" section for an object will create the "Source References" section for an object
""" """
map(self.bibli.add_reference, srcobj.get_source_references()) map(lambda i: self.bibli.add_reference(
self.report.database.get_citation_from_handle(i)),
srcobj.get_citation_list())
sourcerefs = self.display_source_refs(self.bibli) sourcerefs = self.display_source_refs(self.bibli)
# return to its callers # return to its callers
@ -3803,7 +3808,9 @@ class MediaPage(BasePage):
def display_media_sources(self, photo): def display_media_sources(self, photo):
map(self.bibli.add_reference, photo.get_source_references()) map(lambda i: self.bibli.add_reference(
self.report.database.get_citation_from_handle(i)),
photo.get_citation_list())
sourcerefs = self.display_source_refs(self.bibli) sourcerefs = self.display_source_refs(self.bibli)
# return source references to its caller # return source references to its caller
@ -5362,7 +5369,7 @@ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
person_link, person_link,
person_ref.get_relation(), person_ref.get_relation(),
self.dump_notes(person_ref.get_note_list()), self.dump_notes(person_ref.get_note_list()),
self.get_citation_links(person_ref.get_source_references()), self.get_citation_links(person_ref.get_citation_list()),
]: ]:
# get colclass from assoc_row # get colclass from assoc_row
@ -5475,8 +5482,8 @@ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
for name in all_names: for name in all_names:
pname = _nd.display_name(name) pname = _nd.display_name(name)
if name == primary_name: if name == primary_name:
pname += self.get_citation_links(self.person.get_source_references() ) pname += self.get_citation_links(self.person.get_citation_list() )
pname += self.get_citation_links( name.get_source_references() ) pname += self.get_citation_links( name.get_citation_list() )
# if we have just a firstname, then the name is preceeded by ", " # if we have just a firstname, then the name is preceeded by ", "
# which doesn't exactly look very nice printed on the web page # which doesn't exactly look very nice printed on the web page
@ -5514,7 +5521,7 @@ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
for name in all_names: for name in all_names:
call_name = name.get_call_name() call_name = name.get_call_name()
if call_name and call_name != first_name: if call_name and call_name != first_name:
call_name += self.get_citation_links(name.get_source_references() ) call_name += self.get_citation_links(name.get_citation_list() )
trow = Html("tr") + ( trow = Html("tr") + (
Html("td", _("Call Name"), class_ = "ColumnAttribute", inline = True), Html("td", _("Call Name"), class_ = "ColumnAttribute", inline = True),
Html("td", call_name, class_ = "ColumnValue", inline = True) Html("td", call_name, class_ = "ColumnValue", inline = True)
@ -5524,7 +5531,7 @@ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
# display the nickname attribute # display the nickname attribute
nick_name = self.person.get_nick_name() nick_name = self.person.get_nick_name()
if nick_name and nick_name != first_name: if nick_name and nick_name != first_name:
nick_name += self.get_citation_links(self.person.get_source_references() ) nick_name += self.get_citation_links(self.person.get_citation_list() )
trow = Html("tr") + ( trow = Html("tr") + (
Html("td", _("Nick Name"), class_ = "ColumnAttribute", inline = True), Html("td", _("Nick Name"), class_ = "ColumnAttribute", inline = True),
Html("td", nick_name, class_ = "ColumnValue", inline = True) Html("td", nick_name, class_ = "ColumnValue", inline = True)