* src/Filters/Rules/Person/_IsDescendantFamilyOf.py: Rewrite.
svn: r7239
This commit is contained in:
parent
4990fd36ee
commit
d6affc7c07
@ -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
|
||||||
|
@ -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
|
||||||
|
if not inclusive:
|
||||||
|
self.exclude()
|
||||||
|
|
||||||
p = self.db.get_person_from_handle(handle)
|
def reset(self):
|
||||||
for fhandle in p.get_parent_family_handle_list():
|
self.matches = set()
|
||||||
family = self.db.get_family_from_handle(fhandle)
|
|
||||||
for person_handle in [family.get_mother_handle(),family.get_father_handle()]:
|
def apply(self,db,person):
|
||||||
if person_handle:
|
return person.handle in self.matches
|
||||||
if self.search(person_handle,0):
|
|
||||||
return True
|
def add_matches(self,person):
|
||||||
if val:
|
if not person:
|
||||||
for family_handle in p.get_family_handle_list():
|
return
|
||||||
family = self.db.get_family_from_handle(family_handle)
|
|
||||||
if handle == family.get_father_handle():
|
# Add self
|
||||||
spouse_id = family.get_mother_handle()
|
self.matches.add(person.handle)
|
||||||
else:
|
|
||||||
spouse_id = family.get_father_handle()
|
for family_handle in person.get_family_handle_list():
|
||||||
if spouse_id:
|
family = self.db.get_family_from_handle(family_handle)
|
||||||
if self.search(spouse_id,0):
|
|
||||||
return True
|
# Add every child recursively
|
||||||
return False
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user