From 2667c4262fac08fb5e5a34c8c64c548d2bf651f5 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Fri, 21 Jan 2011 12:10:10 +0000 Subject: [PATCH] 4336: Generate a set of filters matching Alternate names, Nickname attribute and a NameType() selector svn: r16420 --- po/POTFILES.in | 4 ++ src/Filters/Rules/Person/Makefile.am | 4 ++ src/Filters/Rules/Person/_HasAlternateName.py | 51 ++++++++++++++++ .../Rules/Person/_HasNameOriginType.py | 58 +++++++++++++++++++ src/Filters/Rules/Person/_HasNameType.py | 57 ++++++++++++++++++ src/Filters/Rules/Person/_HasNickname.py | 50 ++++++++++++++++ src/Filters/Rules/Person/__init__.py | 8 +++ src/gen/lib/person.py | 3 + src/gui/filtereditor.py | 2 + 9 files changed, 237 insertions(+) create mode 100644 src/Filters/Rules/Person/_HasAlternateName.py create mode 100644 src/Filters/Rules/Person/_HasNameOriginType.py create mode 100644 src/Filters/Rules/Person/_HasNameType.py create mode 100644 src/Filters/Rules/Person/_HasNickname.py diff --git a/po/POTFILES.in b/po/POTFILES.in index e0ba05c48..a141582d2 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/Filters/Rules/Person/Makefile.am b/src/Filters/Rules/Person/Makefile.am index 21bfaeda4..bd8236b63 100644 --- a/src/Filters/Rules/Person/Makefile.am +++ b/src/Filters/Rules/Person/Makefile.am @@ -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 \ diff --git a/src/Filters/Rules/Person/_HasAlternateName.py b/src/Filters/Rules/Person/_HasAlternateName.py new file mode 100644 index 000000000..b0f0ee4b9 --- /dev/null +++ b/src/Filters/Rules/Person/_HasAlternateName.py @@ -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 diff --git a/src/Filters/Rules/Person/_HasNameOriginType.py b/src/Filters/Rules/Person/_HasNameOriginType.py new file mode 100644 index 000000000..f15c74b13 --- /dev/null +++ b/src/Filters/Rules/Person/_HasNameOriginType.py @@ -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 ') + 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 diff --git a/src/Filters/Rules/Person/_HasNameType.py b/src/Filters/Rules/Person/_HasNameType.py new file mode 100644 index 000000000..20e8291a2 --- /dev/null +++ b/src/Filters/Rules/Person/_HasNameType.py @@ -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 ') + 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 diff --git a/src/Filters/Rules/Person/_HasNickname.py b/src/Filters/Rules/Person/_HasNickname.py new file mode 100644 index 000000000..5d82358ff --- /dev/null +++ b/src/Filters/Rules/Person/_HasNickname.py @@ -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 diff --git a/src/Filters/Rules/Person/__init__.py b/src/Filters/Rules/Person/__init__.py index c27023d81..dd2e6e399 100644 --- a/src/Filters/Rules/Person/__init__.py +++ b/src/Filters/Rules/Person/__init__.py @@ -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, diff --git a/src/gen/lib/person.py b/src/gen/lib/person.py index 353500448..31b48e5b8 100644 --- a/src/gen/lib/person.py +++ b/src/gen/lib/person.py @@ -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() diff --git a/src/gui/filtereditor.py b/src/gui/filtereditor.py index 02be0e424..0acd891a3 100644 --- a/src/gui/filtereditor.py +++ b/src/gui/filtereditor.py @@ -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, } #-------------------------------------------------------------------------