* src/GenericFilter.py (IsLessThanNthGenerationAncestorOfBookmarked):
Add new filter rule. svn: r5431
This commit is contained in:
parent
c175a467ab
commit
7e0ecb9806
@ -1,3 +1,7 @@
|
||||
2005-11-23 Wayne Bergeron <wb@vallnet.com>
|
||||
* src/GenericFilter.py (IsLessThanNthGenerationAncestorOfBookmarked):
|
||||
Add new filter rule.
|
||||
|
||||
2005-11-23 Alex Roitman <shura@gramps-project.org>
|
||||
* src/ArgHandler.py (cl_export): Add grdb export from the CLI.
|
||||
* src/plugins/Check.py (check_parent_relationships): Step through
|
||||
|
@ -2018,6 +2018,64 @@ class GenericFilter:
|
||||
rule.reset()
|
||||
return res
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# IsLessThanNthGenerationAncestorOfBookmarked
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class IsLessThanNthGenerationAncestorOfBookmarked(Rule):
|
||||
# Submitted by Wayne Bergeron
|
||||
"""Rule that checks for a person that is an ancestor of bookmarked persons
|
||||
not more than N generations away"""
|
||||
|
||||
labels = [ _('Number of generations:') ]
|
||||
name = _('Ancestors of bookmarked people not more '
|
||||
'than <N> generations away')
|
||||
category = _('Ancestral filters')
|
||||
description = _("Matches ancestors of the people on the bookmark list"
|
||||
"not more than N generations away")
|
||||
|
||||
def prepare(self,db):
|
||||
self.db = db
|
||||
bookmarks = self.db.get_bookmarks()
|
||||
if len(bookmarks) == 0:
|
||||
self.apply = lambda db,p : False
|
||||
else:
|
||||
self.map = {}
|
||||
self.bookmarks = sets.Set(bookmarks)
|
||||
self.apply = self.apply_real
|
||||
for self.bookmarkhandle in self.bookmarks:
|
||||
self.init_ancestor_list(self.bookmarkhandle, 1)
|
||||
|
||||
|
||||
def init_ancestor_list(self,handle,gen):
|
||||
# if self.map.has_key(p.get_handle()) == 1:
|
||||
# loop_error(self.orig,p)
|
||||
if not handle:
|
||||
return
|
||||
if gen:
|
||||
self.map[handle] = 1
|
||||
if gen >= int(self.list[0]):
|
||||
return
|
||||
|
||||
p = self.db.get_person_from_handle(handle)
|
||||
fam_id = p.get_main_parents_family_handle()
|
||||
fam = self.db.get_family_from_handle(fam_id)
|
||||
if fam:
|
||||
f_id = fam.get_father_handle()
|
||||
m_id = fam.get_mother_handle()
|
||||
|
||||
if f_id:
|
||||
self.init_ancestor_list(f_id,gen+1)
|
||||
if m_id:
|
||||
self.init_ancestor_list(m_id,gen+1)
|
||||
|
||||
def apply_real(self,db,person):
|
||||
return person.handle in self.map
|
||||
|
||||
def reset(self):
|
||||
self.map = {}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -2119,6 +2177,7 @@ editor_rule_list = [
|
||||
IsAncestorOf,
|
||||
IsAncestorOfFilterMatch,
|
||||
IsLessThanNthGenerationAncestorOf,
|
||||
IsLessThanNthGenerationAncestorOfBookmarked,
|
||||
IsMoreThanNthGenerationAncestorOf,
|
||||
HasCommonAncestorWith,
|
||||
HasCommonAncestorWithFilterMatch,
|
||||
|
Loading…
x
Reference in New Issue
Block a user