Change Source Pages to use the list of sources generated by the first pass that finds objects to be output, and simplify references section on the Source page to use the references passed to it.

svn: r20649
This commit is contained in:
Tim G L Lyons 2012-11-12 10:44:14 +00:00
parent b08ed4c698
commit 21cf42b077

View File

@ -4290,9 +4290,9 @@ class SourcePages(BasePage):
len(source_list) + 1) len(source_list) + 1)
self.SourceListPage(report, title, source_list.keys()) self.SourceListPage(report, title, source_list.keys())
for source_handle in source_list: for item in self.source_dict.iteritems():
report.user.step_progress() report.user.step_progress()
self.SourcePage(report, title, source_handle, source_list, self.SourcePage(report, title, item, source_list,
ppl_handle_list, database_handles_list) ppl_handle_list, database_handles_list)
report.user.end_progress() report.user.end_progress()
@ -4369,19 +4369,15 @@ class SourcePages(BasePage):
# and close the file # and close the file
self.XHTMLWriter(sourcelistpage, of, sio) self.XHTMLWriter(sourcelistpage, of, sio)
def SourcePage(self, report, title, src_handle, src_list, ppl_handle_list, def SourcePage(self, report, title, item, src_list, ppl_handle_list,
database_handles_list): database_handles_list):
self.dbase_ = report.database self.dbase_ = report.database
(src_handle, bkref_list) = item
source = self.dbase_.get_source_from_handle(src_handle) source = self.dbase_.get_source_from_handle(src_handle)
if not source: if not source:
return return
# for use in determining if a citation referent is in the report database?
(db_people_handles, db_family_handles, db_event_handles, db_place_handles,
db_repository_handles, db_media_handles) = database_handles_list
db_source_handles = src_list
self.page_title = source.get_title() self.page_title = source.get_title()
BasePage.__init__(self, report, title, source.get_gramps_id()) BasePage.__init__(self, report, title, source.get_gramps_id())
@ -4453,300 +4449,50 @@ class SourcePages(BasePage):
if repo_list is not None: if repo_list is not None:
sourcedetail += repo_list sourcedetail += repo_list
# get the Source and its Citation Referents too... # Source refernces lsit
the_lists = Utils.get_source_and_citation_referents(src_handle, self.dbase_) # This would normally be simply:
if the_lists: # reflist = self.display_references(bkref_list)
(citation_list, citation_referents_list) = the_lists # but that would simply give references to the citation page
if citation_referents_list: # (which we don't actually generate), so we bypass the citation,
# and refer directly back to the object that referenced the
# begin Source Citation Referents section # citation.
with Html("div", class_ ="subsection", id = "SourceCitationReferents") as section: # Re-order the list of back references into a dictionary keyed by
sourcedetail += section # the Citation Volume/Page number
bkref_dict = defaultdict(set)
# add secion title for bkref in bkref_list:
section += Html("h4", _("Citation References"), inline =True) (object_bkref_path, bkref_name, bkref_gid) = bkref
(object_bkref_name, citation_bkref_name) = bkref_name
ordered1 = Html("ol", class_ = "Col1", role = "Volume-n-Page") bkref_dict[citation_bkref_name].add(
(object_bkref_path, object_bkref_name, bkref_gid))
for (citation_handle, refs) in citation_referents_list:
citation = self.dbase_.get_citation_from_handle(citation_handle) if bkref_dict:
if citation: # begin references division and title
with Html("div", class_ = "subsection", id = "references") as section:
# gets all citation referents no matter on the filters... section += Html("h4", _("References"), inline = True)
(people_list, family_list, event_list, place_list, source_list, media_list, repo_list) = refs
ordered = Html("ol", class_ = "Col1",
role = "Volume-n-Page")
# remove people that are not in this report database... section += ordered
people_list = [person_handle for person_handle in people_list if person_handle in db_people_handles] # Loop round each Citation Volume/Page number
for citation_bkref_name in sorted(bkref_dict,
# Sort the person list by the individual's surname... key=locale.strxfrm):
people_list = sort_people(self.dbase_, people_list) list = Html("li")
ordered += list
list1 = Html("li", citation.get_page()) list += citation_bkref_name
unordered2 = Html("ul", class_ = "Col2", id = "menu", role = "Object Type") ordered2 = Html("ol", type = "a")
list += ordered2
# Citation Referents have Person objects... # Loop round each back reference sorted by the name for
if people_list: # this Volime/Page number
for (path, name, gid) in sorted(
list2 = Html("li") bkref_dict[citation_bkref_name],
key=lambda x:locale.strxfrm(x[1])):
list2.extend( list2 = Html("li")
Html("a", _("People"), href = "#", title = _("People"), inline = True) ordered2 += list2
) # Note. 'path' already has a filename extension
url = self.report.build_url_fname(path, None, self.up)
unordered3 = Html("ul", class_ = "Col3", role = "Surname") list2 += self.person_link(url, name or _UNKNOWN, None, gid = gid)
sourcedetail += section
for (surname, people_handle_list) in people_list:
list3 = Html("li")
list3.extend(
Html("a", surname, href = "#", title = surname, inline = True)
)
unordered4 = Html("ul", class_ = "Col4", role = "Short Name")
for person_handle in people_handle_list:
person = self.dbase_.get_person_from_handle(person_handle)
if person:
url = self.report.build_url_fname_html(person_handle, "ppl", up = self.up)
unordered4.extend(
Html("li", self.person_link(url, person, name_style = False), inline = True)
)
list3 += unordered4
unordered3 += list3
list2 += unordered3
unordered2 += list2
# remove family handles if they are not in this report database?
family_list = [family_handle for family_handle in family_list if family_handle in db_family_handles]
# Citation Referents have Family Objects...
if (self.inc_families and family_list):
list2 = Html("li")
list2.extend(
Html("a", _("Families"), href = "#", title = _("Families"), inline = True)
)
unordered3 = Html("ul", class_ = "Col3", role = "Husband-n-Spouse")
for family_handle in family_list:
family = self.dbase_.get_family_from_handle(family_handle)
if family:
unordered3.extend(
Html("li", self.get_family_string(family))
)
list2 += unordered3
unordered2 += list2
# remove event handles if they are not in this report database...
event_list = [event_handle for event_handle in event_list if event_handle in db_event_handles]
# Citation Referents have Event Objects...
if (self.inc_events and event_list):
list2 = Html("li")
list2.extend(
Html("a", _("Events"), href = "#", title = _("Events"), inline = True)
)
event_handle_list, event_types = build_event_data_by_events(self.dbase_, event_list)
unordered3 = Html("ul", class_ = "Col3", role = "Event Type")
# separate events by their types and then thier event handles
for (event_type, event_list) in sort_event_types(self.dbase_, event_types, event_handle_list):
# sort data_list by date of event and event handle...
event_list = sorted(event_list, key = operator.itemgetter(0, 1))
list3 = Html("li")
list3.extend(
Html("a", event_type, href = "#", title = event_type, inline = True)
)
unordered4 = Html("ul", class_ = "Col4", role = "HyperLinked Event Date")
for (sort_value, event_handle) in event_list:
event = self.dbase_.get_event_from_handle(event_handle)
if event:
event_date = _dd.display(event.get_date_object())
list4 = Html("li")
list4.extend(
Html("a", event_date, href = "#", title = event_date, inline = True)
)
unordered5 = Html("ul", class_ = "Col5")
# marriage or Divorce Event...
if event.get_type() in [gen.lib.EventType.MARRIAGE, gen.lib.EventType.DIVORCE]:
for (classname, newhandle) in self.dbase_.find_backlink_handles(event_handle, ["Family"]):
family = self.dbase_.get_family_from_handle(newhandle)
if (family and newhandle in db_family_handles):
unordered5.extend(
Html("li", self.get_family_string(family))
)
# any other event types...
else:
back_handle_list = self.dbase_.find_backlink_handles(event_handle, ["Person"])
back_handle_list = [(classname, handle) for (classname, handle) in back_handle_list]
if back_handle_list:
if len(back_handle_list) == 1:
for (classname, newhandle) in back_handle_list:
obj = self.dbase_.get_person_from_handle(newhandle)
if obj:
unordered5.extend(
Html("li", self.event_link(event_handle, self.get_name(obj),
uplink = self.up), inline = True)
)
# this occurs when an event has multiple participants...
else:
for (classname, newhandle) in back_handle_list:
obj = self.dbase_.get_person_from_handle(newhandle)
if obj:
unordered5.extend(
Html("li", self.event_link(event_handle, self.get_name(obj),
uplink = self.up), inline = True)
)
list4 += unordered5
unordered4 += list4
list3 += unordered4
unordered3 += list3
list2 += unordered3
unordered2 += list2
# remove place handles if they are not in this report database...
place_list = [place_handle for place_handle in place_list if place_handle in db_place_handles]
# Citation Referents have Place Objects...
if place_list:
list2 = Html("li")
list2.extend(
Html("a", _("Places"), href = "#", title = _("Places"), inline = True)
)
unordered3 = Html("ul", class_ = "Col3", role = "Place Title")
for place_handle in place_list:
place = self.dbase_.get_place_from_handle(place_handle)
if place:
unordered3.extend(
Html("li", self.place_link(place_handle, place.get_title(), uplink = self.up),
inline = True)
)
list2 += unordered3
unordered2 += list2
# remove sources if they are not in this report database...
source_list = [source_handle for source_handle in source_list if source_handle in db_source_handles]
# Citation Referents have Source Objects...
if source_list:
list2 = Html("li")
list2.extend(
Html("a", _("Sources"), href = "#", title = _("Sources"), inline = True)
)
unordered3 = Html("ul", class_ = "Col3", role = "Source Title")
for source_handle in source_list:
source = self.dbase_.get_source_from_handle(source_handle)
if source:
unordered3.extend(
Html("li", self.source_link(source_handle,
source.get_title(), source.get_gramps_id(),
uplink = self.up), inline = True)
)
list2 += unordered3
unordered2 += list2
# remove repositories if they are not in this report database...
repo_list = [repo_handle for repo_handle in repo_list
if repo_handle in db_repository_handles]
# Citation Referents have Repository Objects...
if (inc_repositories and repo_list):
list2 = Html("li")
list2.extend(
Html("a", _("Repositories"), href = "#", title = _("Repositories"), inline = True)
)
unordered3 = Html("ul", class_ = "Col3", role = "Repository Name")
for repository_handle in repo_list:
repository = self.dbase_.get_repository_from_handle(repository_handle)
if repository:
unordered3.extend(
Html("li", self.repository_link(repository_handle, repository.get_name(),
uplink = self.up), inline = True)
)
list2 += unordered3
unordered2 += list2
# remove media if they are not in this report database...
media_list = [media_handle for media_handle in media_list if media_handle in db_media_handles]
# Citation Referents has Media Objects...
if (self.create_media and media_list):
sort = Sort.Sort(self.dbase_)
media_list = sorted(media_list, key = sort.by_media_title_key)
list2 = Html("li")
list2.extend(
Html("a", _("Media"), href = "#", title = _("Media"), inline = True)
)
unordered3 = Html("ul", class_ = "Col3", role = "Media Link")
for media_handle in media_list:
media = self.dbase_.get_object_from_handle(media_handle)
if media:
mime_type = media.get_mime_type()
if mime_type:
if mime_type.startswith("image/"):
real_path, newpath = self.report.prepare_copy_media(media)
newpath = self.report.build_url_fname(newpath, up = self.up)
unordered3.extend(
Html("li", self.media_link(media_handle, newpath, media.get_description(),
self.up, usedescr = False), inline = True)
)
else:
unordered3.extend(
Html("li", self.doc_link(media_handle, media.get_description(),
self.up, usedescr = False), inline = True)
)
list2 += unordered3
unordered2 += list2
list1 += unordered2
ordered1 += list1
section += ordered1
# add clearline for proper styling # add clearline for proper styling
# add footer section # add footer section