NarrativeWeb: bug#4079 -- siblings, pedigree, and children are all sorted if birthorder option is chosen.

svn: r15897
This commit is contained in:
Rob G. Healey 2010-09-13 22:14:02 +00:00
parent 33de80e6fd
commit f479381bfd

View File

@ -4042,17 +4042,25 @@ class IndividualPage(BasePage):
Display an individual's pedigree Display an individual's pedigree
""" """
db = self.report.database db = self.report.database
birthorder = self.report.options["birthorder"]
# Define helper functions # Define helper functions
def children_ped(ol): def children_ped(ol):
if family: if family:
for child_ref in family.get_child_ref_list(): childlist = family.get_child_ref_list()
child_handle = child_ref.ref
if child_handle == self.person.handle: childlist = [child_ref.ref for child_ref in childlist]
children = add_birthdate(db, childlist)
if birthorder:
children = sorted(children)
for birthdate, handle in children:
if handle == self.person.handle:
child_ped(ol) child_ped(ol)
else: else:
child = db.get_person_from_handle(child_handle) child = db.get_person_from_handle(handle)
ol += Html("li") + self.pedigree_person(child) ol += Html("li") + self.pedigree_person(child)
else: else:
child_ped(ol) child_ped(ol)
@ -4415,17 +4423,13 @@ class IndividualPage(BasePage):
ordered = Html("ol") ordered = Html("ol")
tcell += ordered tcell += ordered
sibling = add_birthdate(db, sibling)
if birthorder: if birthorder:
kids = sorted(add_birthdate(db, sibling)) sibling = sorted(sibling)
ordered.extend(
self.display_child_link(child_handle)
for birth_date, child_handle in kids
if child_handle != self.person.handle)
else:
ordered.extend( ordered.extend(
self.display_child_link(child_handle) self.display_child_link(child_handle)
for child_handle in sibling for birth_date, child_handle in sibling
if child_handle != self.person.handle) if child_handle != self.person.handle)
# Also try to identify half-siblings # Also try to identify half-siblings
@ -4484,14 +4488,13 @@ class IndividualPage(BasePage):
## ordered = Html("ol") ## ordered = Html("ol")
## tcell += ordered ## tcell += ordered
## ##
## half_siblings = add_birthdate(db, half_siblings)
## if birthorder: ## if birthorder:
## kids = sorted(add_birthdate(db, half_siblings)) ## half_siblings = sorted(half_siblings)
## ##
## ordered.extend( ## ordered.extend(
## self.display_child_link(child_handle) ## self.display_child_link(child_handle)
## for birth_date, child_handle in kids) ## for birth_date, child_handle in half_siblings)
## else:
## ordered += map(self.display_child_link, half_siblings)
## ##
## # get step-siblings ## # get step-siblings
## if showallsiblings: ## if showallsiblings:
@ -4573,17 +4576,13 @@ class IndividualPage(BasePage):
## ordered = Html("ol") ## ordered = Html("ol")
## tcell += ordered ## tcell += ordered
## ##
## step_siblings = add_birthdate(db, step_siblings)
## if birthorder: ## if birthorder:
## kids = [] ## step_siblings = sorted(step_siblings)
## kids = sorted(add_birthdate(db, step_siblings))
## ##
## ordered.extend( ## ordered.extend(
## self.display_child_link(child_handle) ## self.display_child_link(child_handle)
## for birth_date, child_handle in kids) ## for birth_date, child_handle in step_siblings)
##
## else:
## ordered += map(self.display_child_link,
## step_siblings)
# return parents division to its caller # return parents division to its caller
return section return section
@ -4597,6 +4596,7 @@ class IndividualPage(BasePage):
if not family_list: if not family_list:
return None return None
db = self.report.database db = self.report.database
birthorder = self.report.options["birthorder"]
# begin families division and section title # begin families division and section title
with Html("div", class_ = "subsection", id = "families") as section: with Html("div", class_ = "subsection", id = "families") as section:
@ -4627,14 +4627,13 @@ class IndividualPage(BasePage):
childlist = [child_ref.ref for child_ref in childlist] childlist = [child_ref.ref for child_ref in childlist]
if self.report.options['birthorder']: children = add_birthdate(db, childlist)
kids = sorted(add_birthdate(db, childlist)) if birthorder:
children = sorted(children)
ordered.extend( ordered.extend(
self.display_child_link(child_handle) self.display_child_link(child_handle)
for birth_date, child_handle in kids) for birth_date, child_handle in children)
else:
ordered += map(self.display_child_link, childlist)
# family LDS ordinance list # family LDS ordinance list
famldslist = family.lds_ord_list famldslist = family.lds_ord_list
@ -6444,28 +6443,26 @@ def _has_webpage_extension(url):
""" """
return any(url.endswith(ext) for ext in _WEB_EXT) return any(url.endswith(ext) for ext in _WEB_EXT)
def add_birthdate(db, childlist): def add_birthdate(db, handlelist):
""" """
This will sort a list of child handles in birth order This will sort a list of child handles in birth order
""" """
sorted_children = [] sortable_individuals = []
for child_handle in childlist: for handle in handlelist:
child = db.get_person_from_handle(child_handle) person = db.get_person_from_handle(handle)
# get birth date: if birth_date equals nothing, then generate a fake one? # get birth date: if birth_date equals nothing, then generate a fake one?
birth_ref = child.get_birth_ref() birth_ref = person.get_birth_ref()
birth_date = Date.EMPTY
if birth_ref: if birth_ref:
birth = db.get_event_from_handle(birth_ref.ref) birth = db.get_event_from_handle(birth_ref.ref)
if birth: if birth:
birth_date = birth.get_date_object() birth_date = birth.get_date_object().get_sort_value()
else: sortable_individuals.append((birth_date, handle))
birth_date = Date(2199, 12, 31)
sorted_children.append((birth_date, child_handle))
# return the list of child handles and their birthdates
return sorted_children
# return a list of handles with the individual's birthdate attached
return sortable_individuals
def _find_birth_date(db, person): def _find_birth_date(db, person):
""" """