Add family filter to match twins

svn: r21132
This commit is contained in:
Nick Hall 2013-01-15 18:27:43 +00:00
parent 7672f64221
commit 0b2ccdee6d
3 changed files with 67 additions and 0 deletions

View File

@ -60,6 +60,7 @@ from ._childhasnameof import ChildHasNameOf
from ._childhasidof import ChildHasIdOf from ._childhasidof import ChildHasIdOf
from ._changedsince import ChangedSince from ._changedsince import ChangedSince
from ._hastag import HasTag from ._hastag import HasTag
from ._hastwins import HasTwins
editor_rule_list = [ editor_rule_list = [
AllFamilies, AllFamilies,
@ -89,4 +90,5 @@ editor_rule_list = [
ChildHasIdOf, ChildHasIdOf,
ChangedSince, ChangedSince,
HasTag, HasTag,
HasTwins,
] ]

View File

@ -0,0 +1,64 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2013 Nick Hall
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from ....ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from .. import Rule
from ....lib.childreftype import ChildRefType
#-------------------------------------------------------------------------
#
# HasTwins
#
#-------------------------------------------------------------------------
class HasTwins(Rule):
"""Rule that checks for a family with twins"""
name = _('Families with twins')
description = _("Matches families with twins")
category = _('Child filters')
def apply(self, db, family):
date_list = []
for childref in family.get_child_ref_list():
if int(childref.get_mother_relation()) == ChildRefType.BIRTH:
child = db.get_person_from_handle(childref.ref)
birthref = child.get_birth_ref()
if birthref:
birth = db.get_event_from_handle(birthref.ref)
sortval = birth.get_date_object().get_sort_value()
if sortval != 0:
if sortval in date_list:
return True
else:
date_list.append(sortval)
return False

View File

@ -95,6 +95,7 @@ gramps/gen/filters/rules/family/_hasreltype.py
gramps/gen/filters/rules/family/_hassourcecount.py gramps/gen/filters/rules/family/_hassourcecount.py
gramps/gen/filters/rules/family/_hassourceof.py gramps/gen/filters/rules/family/_hassourceof.py
gramps/gen/filters/rules/family/_hastag.py gramps/gen/filters/rules/family/_hastag.py
gramps/gen/filters/rules/family/_hastwins.py
gramps/gen/filters/rules/family/_isbookmarked.py gramps/gen/filters/rules/family/_isbookmarked.py
gramps/gen/filters/rules/family/_matchesfilter.py gramps/gen/filters/rules/family/_matchesfilter.py
gramps/gen/filters/rules/family/_matchessourceconfidence.py gramps/gen/filters/rules/family/_matchessourceconfidence.py