From 763161065e2ef70b34c39285f6128883e0fe8b5e Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 4 Aug 2006 23:19:59 +0000 Subject: [PATCH] In .: * src/Filters/Rules/Family/__init__.py (editor_rule_list): Import and use new rule. * src/Filters/Rules/Family/Makefile.am (pkgdata_PYTHON): Ship new file. * src/Filters/Rules/Family/_HasAttribute.py: Add new rule. * src/Filters/Rules/Makefile.am (pkgdata_PYTHON): Ship new file. * src/Filters/Rules/_HasAttributeBase.py: Add base module. * src/Filters/Rules/_HasEventBase.py (apply): Use new API. In po: Add new files. svn: r7125 --- gramps2/ChangeLog | 7 ++ gramps2/po/ChangeLog | 1 + gramps2/po/POTFILES.in | 2 + gramps2/src/Filters/Rules/Family/Makefile.am | 1 + .../src/Filters/Rules/Family/_HasAttribute.py | 48 ++++++++++++++ gramps2/src/Filters/Rules/Family/_HasEvent.py | 1 - gramps2/src/Filters/Rules/Family/__init__.py | 2 + gramps2/src/Filters/Rules/Makefile.am | 1 + .../src/Filters/Rules/Person/_HasAttribute.py | 16 +---- .../src/Filters/Rules/_HasAttributeBase.py | 64 +++++++++++++++++++ gramps2/src/Filters/Rules/_HasEventBase.py | 8 ++- 11 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 gramps2/src/Filters/Rules/Family/_HasAttribute.py create mode 100644 gramps2/src/Filters/Rules/_HasAttributeBase.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index a132be342..81ca36d31 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,11 @@ 2006-08-04 Alex Roitman + * src/Filters/Rules/Family/__init__.py (editor_rule_list): Import + and use new rule. + * src/Filters/Rules/Family/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/Filters/Rules/Family/_HasAttribute.py: Add new rule. + * src/Filters/Rules/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/Filters/Rules/_HasAttributeBase.py: Add base module. + * src/Filters/Rules/_HasEventBase.py (apply): Use new API. * src/Filters/Rules/Person/_HasFamilyEvent.py (apply): Use new API. * src/Filters/Rules/Person/_PersonWithIncompleteEvent.py (apply): Do not double-handle birth and death events. diff --git a/gramps2/po/ChangeLog b/gramps2/po/ChangeLog index e7ed1cf25..8b137d5e8 100644 --- a/gramps2/po/ChangeLog +++ b/gramps2/po/ChangeLog @@ -1,5 +1,6 @@ 2006-08-04 Alex Roitman * POTFILES.in: Unlist plugins that are not shipped. + Add new files. 2006-08-03 Alex Roitman * POTFILES.in: Add new files. diff --git a/gramps2/po/POTFILES.in b/gramps2/po/POTFILES.in index b8ac5ab5e..72e0296db 100644 --- a/gramps2/po/POTFILES.in +++ b/gramps2/po/POTFILES.in @@ -372,6 +372,7 @@ src/Filters/_SearchBar.py src/Filters/_SearchFilter.py src/Filters/_SidebarFilter.py src/Filters/Rules/_Everything.py +src/Filters/Rules/_HasAttributeBase.py src/Filters/Rules/_HasEventBase.py src/Filters/Rules/_HasGrampsId.py src/Filters/Rules/_HasNoteRegexBase.py @@ -447,6 +448,7 @@ src/Filters/Rules/Person/_SearchName.py src/Filters/Rules/Family/__init__.py src/Filters/Rules/Family/_AllFamilies.py src/Filters/Rules/Family/_FamilyPrivate.py +src/Filters/Rules/Family/_HasAttribute.py src/Filters/Rules/Family/_HasEvent.py src/Filters/Rules/Family/_HasIdOf.py src/Filters/Rules/Family/_HasNoteMatchingSubstringOf.py diff --git a/gramps2/src/Filters/Rules/Family/Makefile.am b/gramps2/src/Filters/Rules/Family/Makefile.am index 95b5e2b8e..3afc0f6e4 100644 --- a/gramps2/src/Filters/Rules/Family/Makefile.am +++ b/gramps2/src/Filters/Rules/Family/Makefile.am @@ -6,6 +6,7 @@ pkgdata_PYTHON = \ _AllFamilies.py\ _FamilyPrivate.py\ _HasEvent.py\ + _HasAttribute.py\ _HasIdOf.py\ _HasNoteMatchingSubstringOf.py\ _HasNoteRegexp.py\ diff --git a/gramps2/src/Filters/Rules/Family/_HasAttribute.py b/gramps2/src/Filters/Rules/Family/_HasAttribute.py new file mode 100644 index 000000000..95e6180a6 --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_HasAttribute.py @@ -0,0 +1,48 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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: _HasAttribute.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasAttributeBase import HasAttributeBase + +#------------------------------------------------------------------------- +# +# HasAttribute +# +#------------------------------------------------------------------------- +class HasAttribute(HasAttributeBase): + """Rule that checks for a family with a particular family attribute""" + + labels = [ _('Family attribute:'), _('Value:') ] + name = _('Families with the family ') + description = _("Matches families with the family attribute " + "of a particular value") diff --git a/gramps2/src/Filters/Rules/Family/_HasEvent.py b/gramps2/src/Filters/Rules/Family/_HasEvent.py index dc975bca5..c86e0f099 100644 --- a/gramps2/src/Filters/Rules/Family/_HasEvent.py +++ b/gramps2/src/Filters/Rules/Family/_HasEvent.py @@ -48,4 +48,3 @@ class HasEvent(HasEventBase): _('Description:') ] name = _('Families with the ') description = _("Matches families with an event of a particular value") - diff --git a/gramps2/src/Filters/Rules/Family/__init__.py b/gramps2/src/Filters/Rules/Family/__init__.py index 828d0de6c..27a694dd9 100644 --- a/gramps2/src/Filters/Rules/Family/__init__.py +++ b/gramps2/src/Filters/Rules/Family/__init__.py @@ -33,6 +33,7 @@ from _RegExpIdOf import RegExpIdOf from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _FamilyPrivate import FamilyPrivate +from _HasAttribute import HasAttribute from _HasEvent import HasEvent from _MatchesFilter import MatchesFilter from _FatherHasNameOf import FatherHasNameOf @@ -51,6 +52,7 @@ editor_rule_list = [ HasNoteMatchingSubstringOf, FamilyPrivate, HasEvent, + HasAttribute, MatchesFilter, FatherHasNameOf, FatherHasIdOf, diff --git a/gramps2/src/Filters/Rules/Makefile.am b/gramps2/src/Filters/Rules/Makefile.am index 5ae1622db..50e2355c8 100644 --- a/gramps2/src/Filters/Rules/Makefile.am +++ b/gramps2/src/Filters/Rules/Makefile.am @@ -7,6 +7,7 @@ pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules pkgdata_PYTHON = \ _Everything.py\ _HasEventBase.py\ + _HasAttributeBase.py\ _HasGrampsId.py\ _HasNoteRegexBase.py\ _HasNoteSubstrBase.py\ diff --git a/gramps2/src/Filters/Rules/Person/_HasAttribute.py b/gramps2/src/Filters/Rules/Person/_HasAttribute.py index fa55716d9..eec509e44 100644 --- a/gramps2/src/Filters/Rules/Person/_HasAttribute.py +++ b/gramps2/src/Filters/Rules/Person/_HasAttribute.py @@ -32,29 +32,17 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._Rule import Rule +from Filters.Rules._HasAttributeBase import HasAttributeBase #------------------------------------------------------------------------- # # HasAttribute # #------------------------------------------------------------------------- -class HasAttribute(Rule): +class HasAttribute(HasAttributeBase): """Rule that checks for a person with a particular personal attribute""" labels = [ _('Personal attribute:'), _('Value:') ] name = _('People with the personal ') description = _("Matches people with the personal attribute " "of a particular value") - category = _('General filters') - - def apply(self,db,person): - if not self.list[0]: - return False - for attr in person.get_attribute_list(): - name_match = self.list[0] == attr.get_type() - value_match = \ - attr.get_value().upper().find(self.list[1].upper()) != -1 - if name_match and value_match: - return True - return False diff --git a/gramps2/src/Filters/Rules/_HasAttributeBase.py b/gramps2/src/Filters/Rules/_HasAttributeBase.py new file mode 100644 index 000000000..2b40fcab1 --- /dev/null +++ b/gramps2/src/Filters/Rules/_HasAttributeBase.py @@ -0,0 +1,64 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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: _HasAttributeBase.py,v 1.1 2006/08/04 23:08:14 shura Exp $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from RelLib import AttributeType +from Filters.Rules._Rule import Rule + +#------------------------------------------------------------------------- +# +# HasAttribute +# +#------------------------------------------------------------------------- +class HasAttributeBase(Rule): + """Rule that checks for an object with a particular attribute""" + + labels = [ _('Attribute:'), _('Value:') ] + name = _('Objects with the ') + description = _("Matches objects with the given attribute " + "of a particular value") + category = _('General filters') + + def apply(self,db,obj): + if not self.list[0]: + return False + for attr in obj.get_attribute_list(): + specified_type = AttributeType() + specified_type.set_from_xml_str(self.list[0]) + name_match = attr.get_type() == specified_type + + value_match = \ + attr.get_value().upper().find(self.list[1].upper()) != -1 + if name_match and value_match: + return True + return False diff --git a/gramps2/src/Filters/Rules/_HasEventBase.py b/gramps2/src/Filters/Rules/_HasEventBase.py index 0452d1255..fcb313d30 100644 --- a/gramps2/src/Filters/Rules/_HasEventBase.py +++ b/gramps2/src/Filters/Rules/_HasEventBase.py @@ -33,6 +33,7 @@ from gettext import gettext as _ # #------------------------------------------------------------------------- import DateHandler +from RelLib import EventType from Filters.Rules._Rule import Rule from Filters.Rules._RuleUtils import date_cmp @@ -69,8 +70,11 @@ class HasEventBase(Rule): continue event = db.get_event_from_handle(event_ref.ref) val = True - if self.etype and event.get_type() != self.etype: - val = False + if self.etype: + specified_type = EventType() + specified_type.set_from_xml_str(self.etype) + if event.type != specified_type: + val = False if self.list[3] and event.get_description().upper().find( self.list[3].upper())==-1: val = False