3943: Crashed whilst exporting to data.gramps using a person filter 'Public'; fixed many filter rules for people

svn: r15368
This commit is contained in:
Doug Blank 2010-05-09 13:42:33 +00:00
parent 1ff33d6377
commit 2c7e58e187
20 changed files with 99 additions and 74 deletions

View File

@ -75,7 +75,8 @@ def get_family_handle_people(db, exclude_handle, family_handle):
possibly_add_handle(family.get_mother_handle())
for child_ref in family.get_child_ref_list():
possibly_add_handle(child_ref.get_reference_handle())
if child_ref:
possibly_add_handle(child_ref.get_reference_handle())
return people

View File

@ -48,11 +48,12 @@ class FamilyWithIncompleteEvent(Rule):
def apply(self,db,person):
for family_handle in person.get_family_handle_list():
family = db.get_family_from_handle(family_handle)
for event_ref in family.get_event_ref_list():
if event_ref:
event = db.get_event_from_handle(event_ref.ref)
if not event.get_place_handle():
return True
if not event.get_date_object():
return True
if family:
for event_ref in family.get_event_ref_list():
if event_ref:
event = db.get_event_from_handle(event_ref.ref)
if not event.get_place_handle():
return True
if not event.get_date_object():
return True
return False

View File

@ -58,7 +58,9 @@ class HasBirth(Rule):
def apply(self,db,person):
for event_ref in person.get_event_ref_list():
if event_ref.role != EventRoleType.PRIMARY:
if not event_ref:
continue
elif event_ref.role != EventRoleType.PRIMARY:
# Only match primaries, no witnesses
continue
event = db.get_event_from_handle(event_ref.ref)

View File

@ -68,14 +68,15 @@ class HasCommonAncestorWith(Rule):
for fam_handle in person.get_parent_family_handle_list():
fam = db.get_family_from_handle(fam_handle)
for par_handle in (fam.get_father_handle(), fam.get_mother_handle()):
if par_handle:
par = db.get_person_from_handle(par_handle)
if par and par.handle not in self.ancestor_cache:
self.add_ancs(db, par)
if par:
self.ancestor_cache[person.handle].add(par)
self.ancestor_cache[person.handle] |= self.ancestor_cache[par.handle]
if fam:
for par_handle in (fam.get_father_handle(), fam.get_mother_handle()):
if par_handle:
par = db.get_person_from_handle(par_handle)
if par and par.handle not in self.ancestor_cache:
self.add_ancs(db, par)
if par:
self.ancestor_cache[person.handle].add(par)
self.ancestor_cache[person.handle] |= self.ancestor_cache[par.handle]
def reset(self):
self.ancestor_cache = {}

View File

@ -58,7 +58,9 @@ class HasDeath(Rule):
def apply(self,db,person):
for event_ref in person.get_event_ref_list():
if event_ref.role != EventRoleType.PRIMARY:
if not event_ref:
continue
elif event_ref.role != EventRoleType.PRIMARY:
# Only match primaries, no witnesses
continue
event = db.get_event_from_handle(event_ref.ref)

View File

@ -53,10 +53,13 @@ class HasFamilyAttribute(Rule):
return False
for f_id in person.get_family_handle_list():
f = db.get_family_from_handle(f_id)
if not f:
continue
for attr in f.get_attribute_list():
name_match = self.list[0] == attr.get_type()
value_match = \
attr.get_value().upper().find(self.list[1].upper()) != -1
if name_match and value_match:
return True
if attr:
name_match = self.list[0] == attr.get_type()
value_match = \
attr.get_value().upper().find(self.list[1].upper()) != -1
if name_match and value_match:
return True
return False

View File

@ -64,6 +64,8 @@ class HasFamilyEvent(Rule):
def apply(self,db,person):
for f_id in person.get_family_handle_list():
f = db.get_family_from_handle(f_id)
if not f:
continue
for event_ref in f.get_event_ref_list():
if not event_ref:
continue

View File

@ -61,9 +61,10 @@ class HasRelationship(Rule):
# count children and look for a relationship type match
for f_id in person.get_family_handle_list():
f = db.get_family_from_handle(f_id)
cnt = cnt + len(f.get_child_ref_list())
if self.list[1] and specified_type == f.get_relationship():
rel_type = 1
if f:
cnt = cnt + len(f.get_child_ref_list())
if self.list[1] and specified_type == f.get_relationship():
rel_type = 1
# if number of relations specified
if self.list[0]:

View File

@ -171,7 +171,7 @@ class HasTextMatchingSubstringOf(Rule):
self.repo_map.update(
repo.handle for repo in self.db.iter_repositories()
if self.match_object(repo)
if repo and self.match_object(repo)
)

View File

@ -48,9 +48,10 @@ class HaveAltFamilies(Rule):
def apply(self,db,person):
for fhandle in person.get_parent_family_handle_list():
family = db.get_family_from_handle(fhandle)
ref = [ ref for ref in family.get_child_ref_list() \
if ref.ref == person.handle]
if ref[0].get_father_relation() == ChildRefType.ADOPTED \
or ref[0].get_mother_relation() == ChildRefType.ADOPTED:
return True
if family:
ref = [ ref for ref in family.get_child_ref_list() \
if ref.ref == person.handle]
if ref[0].get_father_relation() == ChildRefType.ADOPTED \
or ref[0].get_mother_relation() == ChildRefType.ADOPTED:
return True
return False

View File

@ -47,4 +47,4 @@ class HaveChildren(Rule):
def apply(self,db,person):
for family_handle in person.get_family_handle_list():
family = db.get_family_from_handle(family_handle)
return len(family.get_child_ref_list()) > 0
return family and len(family.get_child_ref_list()) > 0

View File

@ -69,5 +69,6 @@ class IsChildOfFilterMatch(MatchesFilter):
return
for fam_id in person.get_family_handle_list():
fam = self.db.get_family_from_handle(fam_id)
self.map.update(child_ref.ref
for child_ref in fam.get_child_ref_list())
if fam:
self.map.update(child_ref.ref
for child_ref in fam.get_child_ref_list())

View File

@ -83,17 +83,18 @@ class IsDescendantFamilyOf(Rule):
for family_handle in person.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle)
if family:
# Add every child recursively
for child_ref in family.get_child_ref_list():
if child_ref:
self.add_matches(self.db.get_person_from_handle(child_ref.ref))
# Add every child recursively
for child_ref in family.get_child_ref_list():
self.add_matches(self.db.get_person_from_handle(child_ref.ref))
# Add spouse
if person.handle == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
self.matches.add(spouse_handle)
# Add spouse
if person.handle == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
self.matches.add(spouse_handle)
def exclude(self):
# This removes root person and his/her spouses from the matches set
@ -101,8 +102,9 @@ class IsDescendantFamilyOf(Rule):
self.matches.remove(self.root_person.handle)
for family_handle in self.root_person.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle)
if self.root_person.handle == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
self.matches.remove(spouse_handle)
if family:
if self.root_person.handle == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
self.matches.remove(spouse_handle)

View File

@ -75,6 +75,7 @@ class IsLessThanNthGenerationDescendantOf(Rule):
for fam_id in person.get_family_handle_list():
fam = self.db.get_family_from_handle(fam_id)
for child_ref in fam.get_child_ref_list():
self.init_list(
self.db.get_person_from_handle(child_ref.ref), gen+1)
if fam:
for child_ref in fam.get_child_ref_list():
self.init_list(
self.db.get_person_from_handle(child_ref.ref), gen+1)

View File

@ -73,6 +73,7 @@ class IsMoreThanNthGenerationDescendantOf(Rule):
for fam_id in person.get_family_handle_list():
fam = self.db.get_family_from_handle(fam_id)
for child_ref in fam.get_child_ref_list():
self.init_list(
self.db.get_person_from_handle(child_ref.ref), gen+1)
if fam:
for child_ref in fam.get_child_ref_list():
self.init_list(
self.db.get_person_from_handle(child_ref.ref), gen+1)

View File

@ -67,6 +67,9 @@ class IsParentOfFilterMatch(MatchesFilter):
def init_list(self,person):
for fam_id in person.get_parent_family_handle_list():
fam = self.db.get_family_from_handle(fam_id)
self.map.update(parent_id
for parent_id in [fam.get_father_handle(), fam.get_mother_handle()]
if parent_id)
if fam:
self.map.update(parent_id
for parent_id in [fam.get_father_handle(),
fam.get_mother_handle()]
if parent_id)

View File

@ -71,4 +71,4 @@ class IsSiblingOfFilterMatch(MatchesFilter):
if fam:
self.map.update(child_ref.ref
for child_ref in fam.get_child_ref_list()
if child_ref.ref != person.handle)
if child_ref and child_ref.ref != person.handle)

View File

@ -55,11 +55,13 @@ class IsSpouseOfFilterMatch(MatchesFilter):
def apply(self,db,person):
for family_handle in person.get_family_handle_list ():
family = db.get_family_from_handle(family_handle)
for spouse_id in [family.get_father_handle (), family.get_mother_handle ()]:
if not spouse_id:
continue
if spouse_id == person.handle:
continue
if self.filt.apply (db, db.get_person_from_handle( spouse_id)):
return True
if family:
for spouse_id in [family.get_father_handle(),
family.get_mother_handle()]:
if not spouse_id:
continue
if spouse_id == person.handle:
continue
if self.filt.apply (db, db.get_person_from_handle( spouse_id)):
return True
return False

View File

@ -48,7 +48,7 @@ class IsWitness(Rule):
def apply(self,db,person):
for event_ref in person.event_ref_list:
if event_ref.role == EventRoleType.WITNESS:
if event_ref and event_ref.role == EventRoleType.WITNESS:
# This is the witness.
# If event type was given, then check it.
if self.list[0]:

View File

@ -53,10 +53,11 @@ class MissingParent(Rule):
return True
for family_handle in person.get_parent_family_handle_list():
family = db.get_family_from_handle(family_handle)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
if not father_handle:
return True
if not mother_handle:
return True
if family:
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
if not father_handle:
return True
if not mother_handle:
return True
return False