From 354f27f46acf604364170c5e6b31b0058fb9d52c Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 9 Mar 2005 17:47:23 +0000 Subject: [PATCH] * src/GenericFilter.py (IsDefaultPerson,IsSiblingOfFilterMatch): Add filter rules. svn: r4146 --- ChangeLog | 4 +++ src/GenericFilter.py | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/ChangeLog b/ChangeLog index bf5b6d4d8..8e3b0d07e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-03-09 Martin Hawlisch + * src/GenericFilter.py (IsDefaultPerson,IsSiblingOfFilterMatch): + Add filter rules. + 2005-03-09 Don Allingham * srcNameEdit.py: assign date on close diff --git a/src/GenericFilter.py b/src/GenericFilter.py index ee4a20da0..e8017a142 100644 --- a/src/GenericFilter.py +++ b/src/GenericFilter.py @@ -288,6 +288,31 @@ class HasIdOf(Rule): def apply(self,db,p_id): return p_id == self.list[0] +#------------------------------------------------------------------------- +# +# HasIdOf +# +#------------------------------------------------------------------------- +class IsDefaultPerson(Rule): + """Rule that checks for a default person in the database""" + + labels = [] + + def name(self): + return 'Is default person' + + def description(self): + return _("Matches the default person") + + def category(self): + return _('General filters') + + def apply(self,db,p_id): + person = db.get_default_person() + if person: + return p_id == person.get_handle() + return false + #------------------------------------------------------------------------- # # HasCompleteRecord @@ -565,6 +590,51 @@ class IsChildOfFilterMatch(Rule): for child_handle in fam.get_child_handle_list(): self.map[child_handle] = 1 +#------------------------------------------------------------------------- +# +# IsSiblingOfFilterMatch +# +#------------------------------------------------------------------------- +class IsSiblingOfFilterMatch(Rule): + """Rule that checks for a person that is a sibling + of someone matched by a filter""" + + labels = [ _('Filter name:') ] + + def __init__(self,list): + Rule.__init__(self,list) + self.init = 0 + self.map = {} + + def name(self): + return 'Is a sibling of filter match' + + def description(self): + return _("Matches the person that is a sibling of someone matched by a filter") + + def category(self): + return _('Family filters') + + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db + + if not self.init: + self.init = 1 + filt = MatchesFilter(self.list) + for person_handle in db.get_person_handles(sort_handles=False): + if filt.apply (db, person_handle): + self.init_list (person_handle) + return self.map.has_key(p_id) + + def init_list(self,p_id): + p = self.db.get_person_from_handle(p_id) + fam_id = p.get_main_parents_family_handle() + fam = self.db.get_family_from_handle(fam_id) + if fam: + for child_handle in fam.get_child_handle_list(): + self.map[child_handle] = 1 + #------------------------------------------------------------------------- # # IsDescendantFamilyOf @@ -1531,6 +1601,7 @@ class GenericFilter: #------------------------------------------------------------------------- tasks = { unicode(_("Everyone")) : Everyone, + unicode(_("Is default person")) : IsDefaultPerson, unicode(_("Has the Id")) : HasIdOf, unicode(_("Has a name")) : HasNameOf, unicode(_("Has the relationships")) : HasRelationship, @@ -1563,6 +1634,7 @@ tasks = { unicode(_("Has the family attribute")) : HasFamilyAttribute, unicode(_("Matches the filter named")) : MatchesFilter, unicode(_("Is spouse of filter match")) : IsSpouseOfFilterMatch, + unicode(_("Is a sibling of filter match")) : IsSiblingOfFilterMatch, unicode(_("Relationship path between two people")) : RelationshipPathBetween, }