4336: Generate a set of filters matching Alternate names, Nickname attribute and a NameType() selector

svn: r16420
This commit is contained in:
Benny Malengier 2011-01-21 12:10:10 +00:00
parent 81e9d47998
commit 2667c4262f
9 changed files with 237 additions and 0 deletions

View File

@ -427,6 +427,7 @@ src/Filters/Rules/Person/_Disconnected.py
src/Filters/Rules/Person/_Everyone.py
src/Filters/Rules/Person/_FamilyWithIncompleteEvent.py
src/Filters/Rules/Person/_HasAddress.py
src/Filters/Rules/Person/_HasAlternateName.py
src/Filters/Rules/Person/_HasAssociation.py
src/Filters/Rules/Person/_HasAttribute.py
src/Filters/Rules/Person/_HasBirth.py
@ -440,6 +441,9 @@ src/Filters/Rules/Person/_HasGallery.py
src/Filters/Rules/Person/_HasIdOf.py
src/Filters/Rules/Person/_HasLDS.py
src/Filters/Rules/Person/_HasNameOf.py
src/Filters/Rules/Person/_HasNameOriginType.py
src/Filters/Rules/Person/_HasNameType.py
src/Filters/Rules/Person/_HasNickname.py
src/Filters/Rules/Person/_HasNote.py
src/Filters/Rules/Person/_HasNoteMatchingSubstringOf.py
src/Filters/Rules/Person/_HasNoteRegexp.py

View File

@ -10,6 +10,7 @@ pkgdata_PYTHON = \
_FamilyWithIncompleteEvent.py \
_HasAttribute.py \
_HasAddress.py \
_HasAlternateName.py \
_HasAssociation.py \
_HasBirth.py \
_HasCommonAncestorWith.py \
@ -22,6 +23,9 @@ pkgdata_PYTHON = \
_HasIdOf.py \
_HasLDS.py \
_HasNameOf.py \
_HasNameOriginType.py \
_HasNameType.py \
_HasNickname.py \
_HasNote.py \
_HasNoteMatchingSubstringOf.py \
_HasRelationship.py \

View File

@ -0,0 +1,51 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 Gramps
#
# 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
#
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
#-------------------------------------------------------------------------
#
# HasAlternateName
#
#-------------------------------------------------------------------------
class HasAlternateName(Rule):
"""Rule that checks an alternate name"""
name = _('People with an alternate name')
description = _("Matches people with an alternate name")
category = _('General filters')
def apply(self, db, person):
if person.get_alternate_names():
return True
else:
return False

View File

@ -0,0 +1,58 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 Gramps
#
# 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
#
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
from gen.lib import NameOriginType
#-------------------------------------------------------------------------
#
# HasNameOriginType
#
#-------------------------------------------------------------------------
class HasNameOriginType(Rule):
"""Rule that checks the type of Surname origin"""
labels = [ _('Surname origin type:')]
name = _('People with the <Surname origin type>')
description = _("Matches people with a surname origin")
category = _('General filters')
def apply(self, db, person):
if not self.list[0]:
return False
for name in [person.get_primary_name()] + person.get_alternate_names():
for surname in name.get_surname_list():
specified_type = NameOriginType()
specified_type.set_from_xml_str(self.list[0])
if surname.get_origintype() == specified_type:
return True
return False

View File

@ -0,0 +1,57 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 Gramps
#
# 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
#
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
from gen.lib import NameType
#-------------------------------------------------------------------------
#
# HasNameType
#
#-------------------------------------------------------------------------
class HasNameType(Rule):
"""Rule that checks the type of name"""
labels = [ _('Name type:')]
name = _('People with the <Name type>')
description = _("Matches people with a type of name")
category = _('General filters')
def apply(self, db, person):
if not self.list[0]:
return False
for name in [person.get_primary_name()] + person.get_alternate_names():
specified_type = NameType()
specified_type.set_from_xml_str(self.list[0])
if name.get_type() == specified_type:
return True
return False

View File

@ -0,0 +1,50 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 Gramps
#
# 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
#
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
#-------------------------------------------------------------------------
#
# HasNickname
#
#-------------------------------------------------------------------------
class HasNickname(Rule):
"""Rule that checks a nickname"""
name = _('People with a nickname')
description = _("Matches people with a nickname")
category = _('General filters')
def apply(self, db, person):
if person.get_nick_name():
return True
return False

View File

@ -29,6 +29,7 @@ from _Disconnected import Disconnected
from _Everyone import Everyone
from _FamilyWithIncompleteEvent import FamilyWithIncompleteEvent
from _HasAddress import HasAddress
from _HasAlternateName import HasAlternateName
from _HasAssociation import HasAssociation
from _HasAttribute import HasAttribute
from _HasBirth import HasBirth
@ -42,6 +43,9 @@ from _HasGallery import HavePhotos
from _HasIdOf import HasIdOf
from _HasLDS import HasLDS
from _HasNameOf import HasNameOf
from _HasNameOriginType import HasNameOriginType
from _HasNameType import HasNameType
from _HasNickname import HasNickname
from _HasNote import HasNote
from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf
from _HasNoteRegexp import HasNoteRegexp
@ -113,11 +117,15 @@ editor_rule_list = [
IsMale,
IsDefaultPerson,
IsBookmarked,
HasAlternateName,
HasAddress,
HasAssociation,
HasIdOf,
HasLDS,
HasNameOf,
HasNameOriginType,
HasNameType,
HasNickname,
HasRelationship,
HasDeath,
HasBirth,

View File

@ -512,6 +512,9 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase,
self.alternate_names.append(name)
def get_nick_name(self):
for name in [self.get_primary_name()] + self.get_alternate_names():
if name.get_nick_name():
return name.get_nick_name()
for attr in self.attribute_list:
if int(attr.type) == AttributeType.NICKNAME:
return attr.get_value()

View File

@ -98,6 +98,8 @@ _name2typeclass = {
_('Relationship type:') : gen.lib.FamilyRelType,
_('Marker type:') : gen.lib.MarkerType,
_('Note type:') : gen.lib.NoteType,
_('Name type:') : gen.lib.NameType,
_('Surname origin type:'): gen.lib.NameOriginType,
}
#-------------------------------------------------------------------------