8564: Recursion error when filtering for relatives
This commit is contained in:
parent
612c4665ae
commit
9f8ffc5226
@ -63,34 +63,42 @@ class IsRelatedWith(Rule):
|
||||
return person.handle in self.relatives
|
||||
|
||||
|
||||
def add_relative(self, person):
|
||||
"""Recursive function that scans relatives and add them to self.relatives"""
|
||||
if not(person) or person.handle in self.relatives:
|
||||
def add_relative(self, start):
|
||||
"""Non-recursive function that scans relatives and add them to self.relatives"""
|
||||
if not(start):
|
||||
return
|
||||
|
||||
# Add the relative to the list
|
||||
self.relatives.append(person.handle)
|
||||
expand = [start]
|
||||
relatives = {}
|
||||
|
||||
while expand:
|
||||
person = expand.pop()
|
||||
# Add the relative to the list
|
||||
if person is None or (person.handle in relatives):
|
||||
continue
|
||||
relatives[person.handle] = True
|
||||
|
||||
for family_handle in person.get_parent_family_handle_list():
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
# Check Parents
|
||||
for parent_handle in (family.get_father_handle(), family.get_mother_handle()):
|
||||
if parent_handle:
|
||||
self.add_relative(self.db.get_person_from_handle(parent_handle))
|
||||
# Check Sibilings
|
||||
for child_ref in family.get_child_ref_list():
|
||||
self.add_relative(self.db.get_person_from_handle(child_ref.ref))
|
||||
|
||||
for family_handle in person.get_family_handle_list():
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
# Check Spouse
|
||||
for parent_handle in (family.get_father_handle(), family.get_mother_handle()):
|
||||
if parent_handle:
|
||||
self.add_relative(self.db.get_person_from_handle(parent_handle))
|
||||
# Check Children
|
||||
for child_ref in family.get_child_ref_list():
|
||||
self.add_relative(self.db.get_person_from_handle(child_ref.ref))
|
||||
|
||||
return
|
||||
for family_handle in person.get_parent_family_handle_list():
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
# Check Parents
|
||||
for parent_handle in (family.get_father_handle(), family.get_mother_handle()):
|
||||
if parent_handle:
|
||||
expand.append(self.db.get_person_from_handle(parent_handle))
|
||||
# Check Sibilings
|
||||
for child_ref in family.get_child_ref_list():
|
||||
expand.append(self.db.get_person_from_handle(child_ref.ref))
|
||||
|
||||
for family_handle in person.get_family_handle_list():
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
# Check Spouse
|
||||
for parent_handle in (family.get_father_handle(), family.get_mother_handle()):
|
||||
if parent_handle:
|
||||
expand.append(self.db.get_person_from_handle(parent_handle))
|
||||
# Check Children
|
||||
for child_ref in family.get_child_ref_list():
|
||||
expand.append(self.db.get_person_from_handle(child_ref.ref))
|
||||
|
||||
self.relatives = list(relatives.keys())
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user