Fix errors on class SourcePage and write_data_map(). Thank you Tim Lyons for pointing them out to me.

svn: r18709
This commit is contained in:
Rob G. Healey
2012-01-06 05:46:26 +00:00
parent 6b970b3820
commit a011247f52

View File

@@ -424,6 +424,9 @@ def html_escape(text):
return text return text
# table for skipping control chars from XML except 09, 0A, 0D
strip_dict = dict.fromkeys(range(9)+range(11,13)+range(14, 32))
def name_to_md5(text): def name_to_md5(text):
"""This creates an MD5 hex string to be used as filename.""" """This creates an MD5 hex string to be used as filename."""
return md5(text).hexdigest() return md5(text).hexdigest()
@@ -539,6 +542,15 @@ class BasePage(object):
self.inc_families = report.options['inc_families'] self.inc_families = report.options['inc_families']
self.inc_events = report.options['inc_events'] self.inc_events = report.options['inc_events']
# for use in write_data_map()
def fix(self, line):
try:
l = unicode(line)
except:
l = unicode(str(line),errors = 'replace')
l = l.strip().translate(strip_dict)
return html_escape(l)
def display_relationships(self, individual, ppl_handle_list, place_lat_long): def display_relationships(self, individual, ppl_handle_list, place_lat_long):
""" """
Displays a person's relationships ... Displays a person's relationships ...
@@ -1110,15 +1122,15 @@ class BasePage(object):
""" """
writes out the data map for the different objects writes out the data map for the different objects
""" """
if not data_map: if len(data_map) == 0:
return None return None
# begin data map division and section title... # begin data map division and section title...
with Html("div", class_ = "subsection", id = "data_map") as datamapdiv: with Html("div", class_ = "subsection", id = "data_map") as section:
datamapdiv += Html("h4", _("Data Map"), inline = True) section += Html("h4", _("Data Map"), inline = True)
with Html("table", class_ = "infolist") as table: with Html("table", class_ = "infolist") as table:
datamapdiv += table section += table
thead = Html("thead") thead = Html("thead")
table += thead table += thead
@@ -1132,13 +1144,13 @@ class BasePage(object):
tbody = Html("tbody") tbody = Html("tbody")
table += tbody table += tbody
for dataline in data_map: for key in data_map.keys():
trow = Html("tr") + ( trow = Html("tr") + (
Html("td", dataline.key(), class_ = "ColumnAttribute", inline = rue), Html("td", self.fix(key), class_ = "ColumnAttribute", inline = True),
Html("td", dataline.value(), class_ = "ColumnValue", inline = True) Html("td", self.fix(data_map[key]), class_ = "ColumnValue", inline = True)
) )
tbody += trow tbody += trow
return datamapdiv return section
def source_link(self, source, cindex = None, up = False): def source_link(self, source, cindex = None, up = False):
""" """
@@ -4291,9 +4303,12 @@ class SourcePage(BasePage):
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())
inc_events = self.report.options['inc_events']
inc_families = self.report.options['inc_families']
inc_repositories = self.report.options["inc_repository"] inc_repositories = self.report.options["inc_repository"]
db_event_handles = self.dbase_.iter_event_handles()
db_family_handles = self.dbase_.iter_family_handles()
db_place_handles = self.dbase_.iter_place_handles()
db_source_handles = self.dbase_.iter_source_handles()
db_media_object_handles = self.dbase_.iter_media_object_handles()
of = self.report.create_file(source_handle, "src") of = self.report.create_file(source_handle, "src")
self.up = True self.up = True
@@ -4368,6 +4383,7 @@ class SourcePage(BasePage):
# get the Source and its Citation Referents too... # get the Source and its Citation Referents too...
(citation_list, citation_referents_list) = \ (citation_list, citation_referents_list) = \
Utils.get_source_and_citation_referents(source_handle, self.dbase_) Utils.get_source_and_citation_referents(source_handle, self.dbase_)
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:
@@ -4379,8 +4395,18 @@ class SourcePage(BasePage):
# list item 1 cannot be attached until the end..... # list item 1 cannot be attached until the end.....
list1 = Html("li", citation.get_page()) list1 = Html("li", citation.get_page())
# gets all citation referents no matter on the filters...
(people_list, family_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
# isolate and remove references that are not in this report database...
# repositories are NOT removed by filtering yet...
# TODO: fix repositories
family_list = [fhandle for fhandle in family_list if fhandle in db_family_handles]
event_list = [ehandle for ehandle in event_list if ehandle in db_event_handles]
place_list = [phandle for phandle in place_list if phandle in db_place_handles]
source_list = [shandle for shandle in source_list if shandle in db_source_handles]
media_list = [mhandle for mhandle in media_list if mhandle in db_media_object_handles]
# 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?
people_list = [person_handle for person_handle in people_list if check_person_database(person_handle, ppl_handle_list)] people_list = [person_handle for person_handle in people_list if check_person_database(person_handle, ppl_handle_list)]
@@ -4423,7 +4449,7 @@ class SourcePage(BasePage):
list2 += ordered3 list2 += ordered3
# Citation Referents have Family objects... # Citation Referents have Family objects...
if (inc_families and family_list): if (self.inc_families and family_list):
list2 = Html("li", _("Families")) list2 = Html("li", _("Families"))
ordered2 += list2 ordered2 += list2
@@ -4431,9 +4457,10 @@ class SourcePage(BasePage):
# ordered list, Column 3, Husband and Wife... # ordered list, Column 3, Husband and Wife...
ordered3 = Html("ol", class_ = "Col3 HusbandSpouse") ordered3 = Html("ol", class_ = "Col3 HusbandSpouse")
for handle in family_list: for family_handle in family_list:
family = self.dbase_.get_family_from_handle(fhandle) family = self.dbase_.get_family_from_handle(family_handle)
if family: if family:
mother, father = [None] * 2
mother_handle = family.get_mother_handle() mother_handle = family.get_mother_handle()
father_handle = family.get_father_handle() father_handle = family.get_father_handle()
@@ -4442,35 +4469,31 @@ class SourcePage(BasePage):
mother = self.dbase_.get_person_from_handle(mother_handle) mother = self.dbase_.get_person_from_handle(mother_handle)
if mother: if mother:
mother_name = self.get_name(mother) mother_name = self.get_name(mother)
wlink = self.family_link(handle, mother_name, family.get_gramps_id(), self.up) wlink = self.family_link(mother_handle, mother_name, family.get_gramps_id(), self.up)
if (father_handle and check_person_database(father_handle, ppl_handle_list)): 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)
if father: if father:
father_name = self.get_name(father) father_name = self.get_name(father)
hlink = self.family_link(handle, father_name, family.get_gramps_id(), self.up) hlink = self.family_link(family_handle, father_name, family.get_gramps_id(), self.up)
if mother and father: if mother and father:
family_link = "%s %s %s" % (wlink, _("and"), hlink) list3 = Html("li", '%s' % wlink + _("and") + '%s' % hlink)
elif mother: elif mother:
family_link = wlink list3 = wlink
elif father: elif father:
family_link = hlink list3 = hlink
else: ordered3 += list3
family_link = ''
list3 = family_link
ordered3 += lis3
list2 += ordered3 list2 += ordered3
# Citation Referents have Event Objects... # Citation Referents have Event Objects...
if (inc_events and event_list): if (self.inc_events and event_list):
list2 = Html("li", _("Events")) list2 = Html("li", _("Events"))
ordered2 += list2 ordered2 += list2
# get event handles and types for these events... # get event types and the handles that go with them...
event_handle_list, event_types = build_event_data_by_events(self.dbase_, event_list) event_handle_list, event_types = build_event_data_by_events(self.dbase_, event_list)
db_event_handles = self.dbase_.get_event_handles()
# Ordered list 3, Event Types # Ordered list 3, Event Types
ordered3 = Html("ol", class_ = "Col3 EventTypes") ordered3 = Html("ol", class_ = "Col3 EventTypes")
@@ -4490,7 +4513,7 @@ class SourcePage(BasePage):
while data_list: while data_list:
event_handle = data_list[0] event_handle = data_list[0]
event = self.dbase_.get_event_from_handle(event_handle) event = self.dbase_.get_event_from_handle(event_handle)
if (event and event_handle in db_event_handles): if event:
list4 = Html("li", self.event_link(_dd.display(event.get_date_object()) or etype, list4 = Html("li", self.event_link(_dd.display(event.get_date_object()) or etype,
event_handle, event.get_gramps_id(), self.up)) event_handle, event.get_gramps_id(), self.up))
ordered4 += list4 ordered4 += list4
@@ -4500,7 +4523,6 @@ class SourcePage(BasePage):
# Citation Referents have Place objects... # Citation Referents have Place objects...
if place_list: if place_list:
db_place_handles = self.dbase_.iter_place_handles()
list2 = Html("li", _("Places")) list2 = Html("li", _("Places"))
ordered2 += list2 ordered2 += list2
@@ -4508,17 +4530,16 @@ class SourcePage(BasePage):
# Column and list 3, Place Link... # Column and list 3, Place Link...
ordered3 = Html("ol", class_ = "Col3 PlaceLink") ordered3 = Html("ol", class_ = "Col3 PlaceLink")
for handle in place_list: for place_handle in place_list:
place = self.dbase_.get_place_from_handle(handle) place = self.dbase_.get_place_from_handle(place_handle)
if (place and handle in db_place_handles): if place:
list3 = Html("li", self.place_link(handle, place.get_title(), list3 = Html("li", self.place_link(place_handle, place.get_title(),
place.get_gramps_id(), self.up)) place.get_gramps_id(), self.up))
ordered3 += list3 ordered3 += list3
list2 += ordered3 list2 += ordered3
# Citation Referents has Source Objects... # Citation Referents has Source Objects...
if source_list: if source_list:
db_source_handles = self.dbase_.iter_source_handles()
list2 = Html("li", _("Sources")) list2 = Html("li", _("Sources"))
ordered2 += list2 ordered2 += list2
@@ -4526,10 +4547,11 @@ class SourcePage(BasePage):
# Column and list 3, Source Link # Column and list 3, Source Link
ordered3 = Html("ol", class_ = "Col3 SourceLink") ordered3 = Html("ol", class_ = "Col3 SourceLink")
for handle in source_list: for shandle in source_list:
source = self.dbase_.get_source_from_handle(handle) source = self.dbase_.get_source_from_handle(shandle)
if (source and handle in db_source_handles): if source:
list3 = Html("li", self.source_link(source, up = self.up)) list3 = Html("li", self.source_link(source, up = self.up))
ordered3 += list3 ordered3 += list3
list2 += ordered3 list2 += ordered3
@@ -4542,8 +4564,8 @@ class SourcePage(BasePage):
# Column and list 3, Media Link # Column and list 3, Media Link
ordered3 = Html("ol", class_ = "Col3 MediaLink") ordered3 = Html("ol", class_ = "Col3 MediaLink")
for handle in media_list: for photo_handle in media_list:
media = self.dbase_.get_object_from_handle(handle) media = self.dbase_.get_object_from_handle(photo_handle)
if media: if media:
mime_type = media.get_mime_type() mime_type = media.get_mime_type()
@@ -4552,16 +4574,17 @@ class SourcePage(BasePage):
real_path, newpath = self.report.prepare_copy_media(media) real_path, newpath = self.report.prepare_copy_media(media)
newpath = self.report.build_url_fname(newpath, up = True) newpath = self.report.build_url_fname(newpath, up = True)
list3 = Html("li", self.media_link(handle, newpath, media.get_description(), list3 = Html("li", self.media_link(photo_handle, newpath, media.get_description(),
self.up, True)) self.up, False))
except: except:
list3 += _("Media error...") list3 = _("Media error...")
else: else:
try: try:
list3 = Html("li", self.doc_link(handle, media.get_description(), list3 = Html("li", self.doc_link(photo_handle, media.get_description(),
self.up, True)) self.up, False))
except: except:
list3 += _("Media error...") list3 = _("Media error...")
ordered3 += list3 ordered3 += list3
list2 += ordered3 list2 += ordered3
@@ -4572,12 +4595,12 @@ class SourcePage(BasePage):
ordered2 += list2 ordered2 += list2
# Column and list 3, Repository Link... # Column and list 3, Repository Link...
ordered3 = tml("ol", class_ = "Col3 RepositoryLink") ordered3 = Html("ol", class_ = "Col3 RepositoryLink")
for handle in repo_list: for repository_handle in repo_list:
repository = self.dbase_.get_repository_from_handle(handle) repository = self.dbase_.get_repository_from_handle(repository_handle)
if repository: if repository:
list3 = Html("li", self.repository_link(handle, repository.get_name(), list3 = Html("li", self.repository_link(repository_handle, repository.get_name(),
repository.get_gramps_id(), self.up)) repository.get_gramps_id(), self.up))
ordered3 += list3 ordered3 += list3
list2 += ordered3 list2 += ordered3
@@ -6746,18 +6769,29 @@ class NavWebReport(Report):
# build classes SurnameListPage and SurnamePage # build classes SurnameListPage and SurnamePage
self.surname_pages(ind_list) self.surname_pages(ind_list)
# build classes PlaceListPage and PlacePage # build classes FamilyListPage and FamilyPage
self.place_pages(place_list, source_list) if self.inc_families:
self.family_pages(ind_list, place_list, place_lat_long)
# build classes EventListPage and EventPage # build classes EventListPage and EventPage
if self.inc_events: if self.inc_events:
self.event_pages(ind_list) self.event_pages(ind_list)
# build classes FamilyListPage and FamilyPage # build classes PlaceListPage and PlacePage
if self.inc_families: self.place_pages(place_list, source_list)
self.family_pages(ind_list, place_list, place_lat_long)
# build classes ddressBookList and AddressBookPage
if self.inc_addressbook:
self.addressbook_pages(ind_list)
# build classes RepositoryListPage and RepositoryPage
if self.inc_repository:
repolist = self.database.get_repository_handles()
if len(repolist):
self.repository_pages(repolist, source_list)
# build classes SourceListPage and SourcePage # build classes SourceListPage and SourcePage
# has been moved so that all Sources can be found before processing...
self.source_pages(source_list, ind_list) self.source_pages(source_list, ind_list)
# build classes MediaListPage and MediaPage # build classes MediaListPage and MediaPage
@@ -6772,16 +6806,6 @@ class NavWebReport(Report):
# by galleries # by galleries
self.source_pages(source_list, ind_list) self.source_pages(source_list, ind_list)
# build classes ddressBookList and AddressBookPage
if self.inc_addressbook:
self.addressbook_pages(ind_list)
# build classes RepositoryListPage and RepositoryPage
if self.inc_repository:
repolist = self.database.get_repository_handles()
if len(repolist):
self.repository_pages(repolist, source_list)
# if an archive is being used, close it? # if an archive is being used, close it?
if self.archive: if self.archive:
self.archive.close() self.archive.close()
@@ -6997,9 +7021,7 @@ class NavWebReport(Report):
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(event_handle_list))
)
EventListPage(self, self.title, event_types, event_handle_list, ind_list) EventListPage(self, self.title, event_types, event_handle_list, ind_list)
for event_handle in event_handle_list: for event_handle in event_handle_list:
@@ -7008,22 +7030,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 source_handle in source_list:
SourcePage(self, self.title, source_handle, 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
@@ -7061,24 +7067,6 @@ class NavWebReport(Report):
ThumbnailPreviewPage(self, self.title, self.user.step_progress) ThumbnailPreviewPage(self, self.title, self.user.step_progress)
self.user.end_progress() self.user.end_progress()
def base_pages(self):
"""
creates HomePage, ContactPage, DownloadPage, and IntroductionPage
if requested by options in plugin
"""
if self.use_home:
HomePage(self, self.title)
if self.inc_contact:
ContactPage(self, self.title)
if self.inc_download:
DownloadPage(self, self.title)
if self.use_intro:
IntroductionPage(self, self.title)
def repository_pages(self, repolist, source_list): def repository_pages(self, repolist, source_list):
""" """
will create RepositoryPage() and RepositoryListPage() will create RepositoryPage() and RepositoryListPage()
@@ -7153,6 +7141,39 @@ 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 source_handle in source_list:
SourcePage(self, self.title, source_handle, source_list, ppl_handle_list)
self.user.step_progress()
self.user.end_progress()
def base_pages(self):
"""
creates HomePage, ContactPage, DownloadPage, and IntroductionPage
if requested by options in plugin
"""
if self.use_home:
HomePage(self, self.title)
if self.inc_contact:
ContactPage(self, self.title)
if self.inc_download:
DownloadPage(self, self.title)
if self.use_intro:
IntroductionPage(self, self.title)
def build_subdirs(self, subdir, fname, up = False): def build_subdirs(self, subdir, fname, up = False):
""" """
If subdir is given, then two extra levels of subdirectory are inserted If subdir is given, then two extra levels of subdirectory are inserted