3106: Unable to use People with a common ancestor with <filter> match rule
svn: r13648
This commit is contained in:
@@ -56,12 +56,15 @@ class HasCommonAncestorWith(Rule):
|
|||||||
# ancestor list once.
|
# ancestor list once.
|
||||||
# Start with filling the cache for root person (gramps_id in self.list[0])
|
# Start with filling the cache for root person (gramps_id in self.list[0])
|
||||||
self.ancestor_cache = {}
|
self.ancestor_cache = {}
|
||||||
self.root_person = db.get_person_from_gramps_id(self.list[0])
|
root_person = db.get_person_from_gramps_id(self.list[0])
|
||||||
self.add_ancs(db, self.root_person)
|
self.add_ancs(db, root_person)
|
||||||
|
self.with_people = [root_person.handle]
|
||||||
|
|
||||||
def add_ancs(self, db, person):
|
def add_ancs(self, db, person):
|
||||||
if person.handle not in self.ancestor_cache:
|
if person.handle not in self.ancestor_cache:
|
||||||
self.ancestor_cache[person.handle] = set()
|
self.ancestor_cache[person.handle] = set()
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
for fam_handle in person.get_parent_family_handle_list():
|
for fam_handle in person.get_parent_family_handle_list():
|
||||||
fam = db.get_family_from_handle(fam_handle)
|
fam = db.get_family_from_handle(fam_handle)
|
||||||
@@ -78,7 +81,9 @@ class HasCommonAncestorWith(Rule):
|
|||||||
self.ancestor_cache = {}
|
self.ancestor_cache = {}
|
||||||
|
|
||||||
def has_common_ancestor(self, other):
|
def has_common_ancestor(self, other):
|
||||||
if self.ancestor_cache[self.root_person.handle] & self.ancestor_cache[other.handle]:
|
for handle in self.with_people:
|
||||||
|
if self.ancestor_cache[handle] & \
|
||||||
|
self.ancestor_cache[other.handle]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@@ -55,12 +55,22 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith,MatchesFilter):
|
|||||||
HasCommonAncestorWith.__init__(self,list)
|
HasCommonAncestorWith.__init__(self,list)
|
||||||
self.ancestor_cache = {}
|
self.ancestor_cache = {}
|
||||||
|
|
||||||
def init_ancestor_cache(self,db):
|
def prepare(self, db):
|
||||||
|
self.db = db
|
||||||
|
# For each(!) person we keep track of who their ancestors
|
||||||
|
# are, in a set(). So we only have to compute a person's
|
||||||
|
# ancestor list once.
|
||||||
|
# Start with filling the cache for root person (gramps_id in self.list[0])
|
||||||
|
self.ancestor_cache = {}
|
||||||
|
self.with_people = []
|
||||||
filt = MatchesFilter(self.list)
|
filt = MatchesFilter(self.list)
|
||||||
filt.prepare(db)
|
filt.prepare(db)
|
||||||
def init(self, h): self.ancestor_cache[h] = 1
|
|
||||||
for handle in db.get_person_handles(sort_handles=False):
|
for handle in db.get_person_handles(sort_handles=False):
|
||||||
if (handle not in self.ancestor_cache
|
person = db.get_person_from_handle(handle)
|
||||||
and filt.apply (db, db.get_person_from_handle(handle))):
|
if filt.apply (db, person):
|
||||||
for_each_ancestor(db,[handle],init,self)
|
#store all people in the filter so as to compare later
|
||||||
|
self.with_people.append(person.handle)
|
||||||
|
#fill list of ancestor of person if not present yet
|
||||||
|
if handle not in self.ancestor_cache:
|
||||||
|
self.add_ancs(db, person)
|
||||||
filt.reset()
|
filt.reset()
|
||||||
|
Reference in New Issue
Block a user