* src/Filters/Rules/Person/_IsDescendantFamilyOf.py: Rewrite.

svn: r7239
This commit is contained in:
Alex Roitman 2006-08-22 18:52:37 +00:00
parent 4990fd36ee
commit d6affc7c07
2 changed files with 56 additions and 31 deletions

View File

@ -1,4 +1,5 @@
2006-08-22 Alex Roitman <shura@gramps-project.org> 2006-08-22 Alex Roitman <shura@gramps-project.org>
* src/Filters/Rules/Person/_IsDescendantFamilyOf.py: Rewrite.
* src/Filters/_FilterParser.py (startElement): Upgrade existing * src/Filters/_FilterParser.py (startElement): Upgrade existing
custom_filters file from Media to MediaObject. custom_filters file from Media to MediaObject.
* src/Selectors/_SelectEvent.py (get_handle_column): Correct * src/Selectors/_SelectEvent.py (get_handle_column): Correct

View File

@ -26,6 +26,10 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
try:
set()
except NameError:
from sets import Set as set
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -43,41 +47,61 @@ class IsDescendantFamilyOf(Rule):
"""Rule that checks for a person that is a descendant or the spouse """Rule that checks for a person that is a descendant or the spouse
of a descendant of a specified person""" of a descendant of a specified person"""
labels = [ _('ID:') ] labels = [ _('ID:'), _('Inclusive:') ]
name = _('Descendant family members of <person>') name = _('Descendant family members of <person>')
category = _('Descendant filters') category = _('Descendant filters')
description = _("Matches people that are descendants or the spouse " description = _("Matches people that are descendants or the spouse "
"of a descendant of a specified person") "of a descendant of a specified person")
def apply(self,db,person): def prepare(self,db):
self.map = {}
self.orig_handle = person.handle
self.db = db self.db = db
return self.search(person.handle,1) self.matches = set()
self.root_person = db.get_person_from_gramps_id(self.list[0])
def search(self,handle,val): self.add_matches(self.root_person)
try: try:
if handle == self.db.get_person_from_gramps_id(self.list[0]).get_handle(): if int(self.list[1]):
self.map[handle] = 1 inclusive = True
return True else:
except: inclusive = False
return False except IndexError:
inclusive = True
p = self.db.get_person_from_handle(handle) if not inclusive:
for fhandle in p.get_parent_family_handle_list(): self.exclude()
family = self.db.get_family_from_handle(fhandle)
for person_handle in [family.get_mother_handle(),family.get_father_handle()]: def reset(self):
if person_handle: self.matches = set()
if self.search(person_handle,0):
return True def apply(self,db,person):
if val: return person.handle in self.matches
for family_handle in p.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle) def add_matches(self,person):
if handle == family.get_father_handle(): if not person:
spouse_id = family.get_mother_handle() return
else:
spouse_id = family.get_father_handle() # Add self
if spouse_id: self.matches.add(person.handle)
if self.search(spouse_id,0):
return True for family_handle in person.get_family_handle_list():
return False family = self.db.get_family_from_handle(family_handle)
# 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)
def exclude(self):
# This removes root person and his/her spouses from the matches set
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)