class SourcePage is now ready.

svn: r18673
This commit is contained in:
Rob G. Healey 2011-12-31 23:46:54 +00:00
parent dd653e7abb
commit c8fe7f72f2

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#!/usr/bin/env python #!/usr/bin/env python
# #
@ -1831,8 +1830,8 @@ class BasePage(object):
self.report.user.warn(_("Could not add photo to page"), str(msg)) self.report.user.warn(_("Could not add photo to page"), str(msg))
else: else:
# begin hyperlink # begin hyperlink
snapshot += self.doc_link(photo_handle, descr, up=True, snapshot += self.doc_link(photo_handle, descr, up = True,
usedescr=False) usedescr = False)
lnk = (self.report.cur_fname, self.page_title, self.gid) lnk = (self.report.cur_fname, self.page_title, self.gid)
# FIXME. Is it OK to add to the photo_list of report? # FIXME. Is it OK to add to the photo_list of report?
@ -2256,7 +2255,7 @@ class BasePage(object):
# return hyperlink to its caller # return hyperlink to its caller
return hyper return hyper
def media_link(self, handle, img_url, name, up, usedescr =True): def media_link(self, handle, img_url, name, up, usedescr = True):
""" """
creates and returns a hyperlink to the thumbnail image creates and returns a hyperlink to the thumbnail image
@ -4331,210 +4330,231 @@ class SourcePage(BasePage):
sourcedetail += section sourcedetail += section
section += Html("h4", _("Citation References"), inline =True) section += Html("h4", _("Citation References"), inline =True)
# ordered list (ol) # ordered list #1, Citation Reference Page...
ordered = Html("ol") ordered1 = Html("ol", class_ = "Col1 - CitationReference")
section += ordered section += ordered1
for (citation_handle, refs) in citation_referents_list: for (citation_handle, refs) in citation_referents_list:
citation = self.dbase_.get_citation_from_handle(citation_handle) citation = self.dbase_.get_citation_from_handle(citation_handle)
if citation: if citation:
list = Html("li", citation.get_page())
ordered += list
# if citation references? # list item 1 cannot be attached until the end.....
list1 = Html("li", citation.get_page())
# is there citation references?
if refs: if refs:
(ppl_list, fml_list, event_list, place_list, source_list, media_list, repo_list) = refs (people_list, family_list, event_list, place_list, source_list, media_list, repo_list) = refs
# ordered list #2, Object Type...
ordered2 = Html("ol", class_ = "Col2 - ObjectType")
# Citation Referents have Person objects... # Citation Referents have Person objects...
if ppl_list: if people_list:
list2 = Html("li", _("Person(s)"))
ordered2 += list2
# only add the person handle if the individual is in the report database, and reove any duplication if any? # only add the person handle if the individual is in the report database, and reove any duplication if any?
ppl_list = [phandle for phandle in ppl_list if check_person_database(phandle, ppl_handle_list)] ppl_list = [phandle for phandle in people_list if check_person_database(phandle, ppl_handle_list)]
# Sort the person list by the individual's surname... # Sort the person list by the individual's surname...
ppl_list = sort_people(self.dbase_, ppl_list) ppl_list = sort_people(self.dbase_, ppl_list)
ordered1 = Html("ol") # ordered list #3, Surname...
list1 = Html("li", _("Person(s)")) ordered3 = Html("ol", class_ = "Col3 - Surname")
ordered1 += list1
displayed = []
for (surname, handle_list) in ppl_list: for (surname, handle_list) in ppl_list:
if surname not in displayed:
ordered2 = Html("ol") list3 = Html("li", surname)
list1 += ordered2
list2 = Html("li", surname)
ordered2 += list2
ordered3 = Html("ol")
for person_handle in handle_list:
_obj = self.dbase_.get_person_from_handle(person_handle)
if _obj:
url = self.report.build_url_fname_html(person_handle, "ppl", up = True)
list3 = Html("li") + self.person_link(url, _obj, _NAME_STYLE_DEFAULT,
gid = _obj.get_gramps_id())
ordered3 += list3 ordered3 += list3
# ordered list #4, full name...
ordered4 = Html("ol", clss_ = "Col4 - FullName")
for handle in handle_list:
individual = self.dbase_.get_person_from_handle(handle)
if individual:
url = self.report.build_url_fname_html(handle, "ppl", up = True)
list4 = Html("li", self.person_link(url, individual, _NAME_STYLE_DEFAULT,
gid = individual.get_gramps_id()))
ordered4 += list4
list3 += ordered4
displayed.append(surname)
list2 += ordered3 list2 += ordered3
list += ordered1
# Citation Referents have Family objects... # Citation Referents have Family objects...
if fml_list: if family_list:
ffml_list = set([fhandle for fhandle in fml_list])
ordered1 = Html("ol") list2 = Html("li", _("Families"))
list1 = Html("li", _("Families")) ordered2 += list2
ordered1 += list1
ordered2 = Html("ol") # ordered list, Column 3, Husband and Wife...
list1 += ordered2 ordered3 = Html("ol", class_ = "Col3 - Partners")
for fhandle in fml_list: for handle in family_list:
_obj = self.dbase_.get_family_from_handle(fhandle) family = self.dbase_.get_family_from_handle(fhandle)
if _obj: if family:
list2 = Html("li")
father_handle = _obj.get_father_handle() father_handle = family.get_father_handle()
mother_handle = _obj.get_mother_handle() mother_handle = family.get_mother_handle()
if father_handle:
if (father_handle and check_person_database(father_handle, ppl_handle_list)):
father = self.dbase_.get_person_from_handle(father_handle) father = self.dbase_.get_person_from_handle(father_handle)
father_name = self.get_name(father)
if mother_handle:
mother = self.dbase_.get_person_from_handle(mother_handle)
mother_name = self.get_name(mother)
if mother and father:
use_link = check_person_database(father_handle, ppl_handle_list)
if use_link:
url = self.report.build_url_fname_html(father_handle, "ppl", up = True)
hlink = Html("span", self.person_link(father, father_handle,
_NAME_STYLE_DEFAULT), class_ = "father fatherNmother")
else:
hlink = father_name
use_link = check_person_database(mother_handle, ppl_handle_list) if (mother_handle and check_person_database(mother_handle, ppl_handle_list)):
if use_link: mother = self.dbase_.get_person_from_handle(mother_handle)
if mother and father:
url = self.report.build_url_fname_html(mother_handle, "ppl", up = True) url = self.report.build_url_fname_html(mother_handle, "ppl", up = True)
hlink += Html("span", self.person_link(mother, mother_handle, wlink = Html("li", self.person_link(url, mother, _NAME_STYLE_DEFAULT,
_NAME_STYLE_DEFAULT), class_ = "Nmother") gid = mother.get_gramps_id()))
else:
hlink += mother_name url = self.report.build_url_fname_html(father_handle, "ppl", up = True)
hlink = Html("li", self.person_link(url, father, _NAME_STYLE_DEFAULT,
gid = father.get_gramps_id()))
elif mother: elif mother:
use_link = check_person_database(mother_handle, ppl_handle_list)
if use_link:
url = self.report.build_url_fname_html(mother_handle, "ppl", up = True) url = self.report.build_url_fname_html(mother_handle, "ppl", up = True)
hlink = Html("span", self.person_link(mother, mother_handle, wlink = Html("li", self.person_link(url, mother, _NAME_STYLE_DEFAULT,
_NAME_STYLE_DEFAULT), class_ = "Nmother") gid = mother.get_gramps_id()))
else:
hlink = mother_name
elif father: elif father:
use_link = check_person_database(father_handle, ppl_handle_list)
if use_link:
url = self.report.build_url_fname_html(father_handle, "ppl", up = True) url = self.report.build_url_fname_html(father_handle, "ppl", up = True)
hlink = Html("span", self.person_link(father, father_handle, hlink = Html("li", self.person_link(url, father, _NAME_STYLE_DEFAULT,
_NAME_STYLE_DEFAULT), class_ = "father") gid = father.get_gramps_id()))
else: else:
hlink = father_name wlink = ' '
list2 += hlink hlink = ' '
ordered1 += list2 list3 = Html("li", '%s' + _("and") + '%s' % (wlink, hlink))
list += ordered1 ordered3 += lis3
list2 += ordered3
# Citation Referents have Event objects... # Citation Referents have Event Objects...
if event_list: if event_list:
event_list = set([evt_handle for evt_handle in event_list])
ordered1 = Html("ol") list2 = Html("li", _("Events"))
list1 = Html("li", _("Events"))
ordered1 += list1
ordered2 = Html("ol")
list1 += ordered2
for evt_handle in event_list:
_obj = self.dbase_.get_event_from_handle(evt_handle)
if _obj:
list2 = Html("li") + self.event_link(_obj.get_type(), evt_handle,
gid = _obj.get_gramps_id(), up =True)
ordered2 += list2 ordered2 += list2
list += ordered1
# get event handles and types for these events...
event_handle_list, event_types = build_event_data(self.dbase_, event_list)
db_event_handles = self.dbase_.get_event_handles()
# Ordered list 3, Event Types
ordered3 = Html("ol", class_ = "Col3 - EventTypes")
# separate events by their types and then thier event handles
for (etype, handle_list) in sort_event_types(self.dbase_, event_types, event_handle_list):
list3 = Html("li", etype)
ordered3 += list3
# Ordered list4, Event Date...
ordered4 = Html("ol", class_ = "Col4 - EventDate")
for handle in handle_list:
event = self.dbase_.get_event_from_handle(handle)
if (event and handle in db_event_handles):
list4 = Html("li", self.event_link(_dd.display(event.get_date_object()) or etype,
handle, event.get_gramps_id(), self.up))
ordered4 += list4
list3 += ordered4
list2 += ordered3
# Citation Referents have Place objects... # Citation Referents have Place objects...
if place_list: if place_list:
place_list = set([plc_handle for plc_handle in place_list]) db_place_handles = self.dbase_.iter_place_handles()
ordered1 = Html("ol") list2 = Html("li", _("Places"))
list1 = Html("li", _("Places"))
ordered1 += list1
ordered2 = Html("ol")
list1 += ordered2
for plc_handle in place_list:
_obj = self.dbase_.get_place_from_handle(plc_handle)
if _obj:
list2 = Html("li") + self.place_link(plc_handle, _obj.get_title(), up = True)
ordered2 += list2 ordered2 += list2
list += ordered1
# Citation Referents have Source objects... # Column and list 3, Place Link...
ordered3 = Html("ol", class_ = "Col3 - PlaceLink")
for place_handle in place_list:
place = self.dbase_.get_place_from_handle(place_handle)
if (place and place_handle in db_place_handles):
list3 = Html("li", self.place_link(place_handle, place.get_title(),
place.get_gramps_id(), self.up))
ordered3 += list3
list2 += ordered3
# Citation Referents has Source Objects...
if source_list: if source_list:
source_list = set([src_handle for src_handle in source_list]) db_source_handles = self.dbase_.iter_source_handles()
ordered1 = Html("ol") list2 = Html("li", _("Sources"))
list1 = Html("li", _("Sources"))
ordered1 += list1
ordered2 = Html("ol")
list1 += ordered2
for src_handle in source_list:
_obj = self.dbase_.get_source_from_handle(src_handle)
if _obj:
list2 = Html("li") + self.source_link(_obj, up = True)
ordered2 += list2 ordered2 += list2
list += ordered1
# Citation Referents have Media objects... # Column and list 3, Source Link
if media_list: ordered3 = Html("ol", class_ = "Col3 - SourceLink")
media_list = set([mhandle for mhandle in media_list])
ordered1 = Html("ol") for source_handle in source_list:
list1 = Html("li", _("Media")) source = self.dbase_.get_source_from_handle(source_handle)
ordered1 += list1 if (source and source_handle in db_source_handles):
ordered2 = Html("ol") list3 = Html("li", self.source_link(source, up = self.up))
list1 += ordered2 ordered3 += list3
list2 += ordered3
for mhandle in media_list: # Citation Referents have Media Objects...
_obj = self.dbase_.get_object_from_handle(mhandle) if (self.create_media and media_list):
if _obj:
real_path, newpath = self.report.prepare_copy_media(_obj)
ewpath = self.report.build_url_fname(newpath, up = True)
list2 = Html("li") + self.media_link(mhandle, list2 = Html("li", _("Media"))
newpath, _obj.get_description(), up = True)
ordered2 += list2 ordered2 += list2
list += ordered1
# Citation Referents have Repository objects... # Column and list 3, Media Link
if repo_list: ordered3 = Html("ol", class_ = "Col3 - MediaLink")
repo_list = set([rhandle for rhandle in repo_list])
ordered1 = Html("ol") for handle in media_list:
list1 = Html("li", _("Repositories")) media = self.dbase_.get_object_from_handle(handle)
ordered1 += list1 if media:
ordered2 = Html("ol") mime_type = media.get_mime_type()
list1 += ordered2 if mime_type:
try:
real_path, newpath = self.report.prepare_copy_media(media)
newpath = self.report.build_url_fname(newpath, up = True)
list3 = Html("li", self.media_link(handle, newpath, media.get_description(),
self.up, False))
except:
list3 += _("Media error...")
else:
try:
list3 = Html("li", self.doc_link(handle, media.get_description(),
self.up, False))
except:
list3 += _("Media error...")
ordered3 += list3
list2 += ordered3
# Citation Referents have Repository Objects...
if (self.inc_repositories and repo_list):
list2 = Html("li", _("Repositories"))
ordered2 += list2
# Column and list 3, Repository Link...
ordered3 = tml("ol", class_ = "Col3 - RepositoryLink")
for repo_handle in repo_list: for repo_handle in repo_list:
_obj = self.dbase_.get_repository_from_handle(repo_handle) repository = self.dbase_.get_repository_from_handle(repo_handle)
if _obj: if repository:
list2 = Html("li") + self.repository_link(repo_handle, _obj.get_name(), up = True)
ordered2 += list2 list3 = Html("li", self.repository_link(repo_handle, repository.get_name(), True,
list += ordered1 repository.get_gramps_id(), self.up))
ordered3 += list3
list2 += ordered3
list1 += ordered2
ordered1 += list1
# add clearline for proper styling # add clearline for proper styling
# add footer section # add footer section
@ -6901,23 +6921,6 @@ class NavWebReport(Report):
self.user.step_progress() self.user.step_progress()
self.user.end_progress() self.user.end_progress()
def source_pages(self, source_list, ppl_handle_list):
"""
creates SourceListPage and SourcePage
"""
self.user.begin_progress(_("Narrated Web Site Report"),
_("Creating source pages"),
len(source_list))
SourceListPage(self, self.title, source_list.keys())
for shandle in source_list:
source = self.database.get_source_from_handle(shandle)
SourcePage(self, self.title, source, shandle, source_list, ppl_handle_list)
self.user.step_progress()
self.user.end_progress()
def family_pages(self, ppl_handle_list, place_list, place_lat_long): def family_pages(self, ppl_handle_list, place_list, place_lat_long):
""" """
creates the FamiliesListPage and FamilyPages creates the FamiliesListPage and FamilyPages
@ -6961,11 +6964,13 @@ class NavWebReport(Report):
a dump of all the events sorted by event type, date, and surname a dump of all the events sorted by event type, date, and surname
for classes EventListPage and EventPage for classes EventListPage and EventPage
""" """
self.dbase_ = self.database
# set up progress bar for event pages; using ind list # set up progress bar for event pages; using ind list
event_handle_list, event_types = build_event_data(self.database, ind_list) event_handle_list, event_types = build_event_data(self.dbase_, self.dbase_.iter_event_handles())
self.user.begin_progress(_("Narrated Web Site Report"), self.user.begin_progress(_("Narrated Web Site Report"),
_("Creating event pages"), _("Creating event pages"),
len(event_handle_list)) len(self.dbase_.get_event_handles()))
# send all data to the events list page # send all data to the events list page
EventListPage(self, self.title, event_types, event_handle_list, ind_list) EventListPage(self, self.title, event_types, event_handle_list, ind_list)
@ -6976,6 +6981,23 @@ class NavWebReport(Report):
self.user.step_progress() self.user.step_progress()
self.user.end_progress() self.user.end_progress()
def source_pages(self, source_list, ppl_handle_list):
"""
creates SourceListPage and SourcePage
"""
self.user.begin_progress(_("Narrated Web Site Report"),
_("Creating source pages"),
len(source_list))
SourceListPage(self, self.title, source_list.keys())
for shandle in source_list:
source = self.database.get_source_from_handle(shandle)
SourcePage(self, self.title, source, shandle, source_list, ppl_handle_list)
self.user.step_progress()
self.user.end_progress()
def media_pages(self, source_list): def media_pages(self, source_list):
""" """
creates MediaListPage and MediaPage creates MediaListPage and MediaPage
@ -8124,42 +8146,19 @@ def _find_death_date(dbase, individual):
break break
return date_out return date_out
def build_event_data(dbase, ppl_handle_list): def build_event_data(dbase_, event_handles):
""" """
creates a list of event handles and event types for this database creates a list of event handles and event types for these event handles
""" """
event_handle_list = [] event_handle_list = []
event_types = [] event_types = []
for phandle in ppl_handle_list: for event_handle in event_handles:
person = dbase.get_person_from_handle(phandle) event = dbase_.get_event_from_handle(event_handle)
if person:
evt_ref_list = person.get_event_ref_list()
if evt_ref_list:
for evt_ref in evt_ref_list:
event = dbase.get_event_from_handle(evt_ref.ref)
if event: if event:
event_types.append(str(event.get_type())) event_types.append(str(event.get_type()))
event_handle_list.append(evt_ref.ref) event_handle_list.append(event_handle)
person_family_handle_list = person.get_family_handle_list()
if person_family_handle_list:
for fhandle in person_family_handle_list:
family = dbase.get_family_from_handle(fhandle)
if family:
family_evt_ref_list = family.get_event_ref_list()
if family_evt_ref_list:
for evt_ref in family_evt_ref_list:
event = dbase.get_event_from_handle(evt_ref.ref)
if event:
event_types.append(str(event.type))
event_handle_list.append(evt_ref.ref)
# return event_handle_list and event types to its caller
return event_handle_list, event_types return event_handle_list, event_types
def check_person_database(phandle, ppl_handle_list): def check_person_database(phandle, ppl_handle_list):