* src/Filters/_GenericFilter.py (GenericFilterFactory): Add

factory function.
	* src/Filters/_FilterParser.py (FilterParser.startElement): Use
	factory function.
	* src/Filters/Rules/_MatchesFilterBase.py: Add base module.
	* src/Filters/Rules/Person/_MatchesFilter.py: Derive from base.
	* src/Filters/Rules/Family/_MatchesFilter.py: Add rule.
	* src/Filters/Rules/Family/_MotherHasIdOf.py: Add rule.
	* src/Filters/Rules/Family/_FatherHasIdOf.py: Add rule.
	* src/Filters/Rules/Family/_MotherHasNameOf.py: Add rule.
	* src/Filters/Rules/Family/_ChildHasIdOf.py: Add rule.
	* src/Filters/Rules/Family/_FatherHasNameOf.py: Add rule.
	* src/Filters/Rules/Family/_ChildHasNameOf.py: Add rule.
	* src/Filters/Rules/Family/__init__.py: Expose new rules.
	


svn: r7117
This commit is contained in:
Alex Roitman 2006-08-04 05:05:59 +00:00
parent b6be1b4369
commit 929c918486
13 changed files with 500 additions and 44 deletions

View File

@ -1,4 +1,19 @@
2006-08-03 Alex Roitman <shura@gramps-project.org> 2006-08-03 Alex Roitman <shura@gramps-project.org>
* src/Filters/_GenericFilter.py (GenericFilterFactory): Add
factory function.
* src/Filters/_FilterParser.py (FilterParser.startElement): Use
factory function.
* src/Filters/Rules/_MatchesFilterBase.py: Add base module.
* src/Filters/Rules/Person/_MatchesFilter.py: Derive from base.
* src/Filters/Rules/Family/_MatchesFilter.py: Add rule.
* src/Filters/Rules/Family/_MotherHasIdOf.py: Add rule.
* src/Filters/Rules/Family/_FatherHasIdOf.py: Add rule.
* src/Filters/Rules/Family/_MotherHasNameOf.py: Add rule.
* src/Filters/Rules/Family/_ChildHasIdOf.py: Add rule.
* src/Filters/Rules/Family/_FatherHasNameOf.py: Add rule.
* src/Filters/Rules/Family/_ChildHasNameOf.py: Add rule.
* src/Filters/Rules/Family/__init__.py: Expose new rules.
* src/GrampsLogger/_ErrorReportAssistant.py (build_page5): Typo. * src/GrampsLogger/_ErrorReportAssistant.py (build_page5): Typo.
* src/Filters/Rules/Person/_HasIdOf.py: Cleanup. * src/Filters/Rules/Person/_HasIdOf.py: Cleanup.
* src/Filters/Rules/Person/__init__.py (editor_rule_list): Add * src/Filters/Rules/Person/__init__.py (editor_rule_list): Add

View File

@ -0,0 +1,56 @@
#
# 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: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules import HasGrampsId
#-------------------------------------------------------------------------
#
# HasNameOf
#
#-------------------------------------------------------------------------
class ChildHasIdOf(HasGrampsId):
"""Rule that checks for a person with a specific GRAMPS ID"""
labels = [ _('Person ID:') ]
name = _('Families with child with the <Id>')
description = _("Matches familis where child has a specified "
"GRAMPS ID")
category = _('Child filters')
def apply(self,db,family):
for child_ref in family.get_child_ref_list():
child = db.get_person_from_handle(child_ref.ref)
if HasGrampsId.apply(self,db,child):
return True
return False

View File

@ -0,0 +1,55 @@
#
# 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: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules.Person import HasNameOf
#-------------------------------------------------------------------------
#
# HasNameOf
#
#-------------------------------------------------------------------------
class ChildHasNameOf(HasNameOf):
"""Rule that checks for full or partial name matches"""
name = _('Families with child with the <name>')
description = _("Matches familis where child has a specified "
"(partial) name")
category = _('Child filters')
def apply(self,db,family):
for child_ref in family.get_child_ref_list():
child = db.get_person_from_handle(child_ref.ref)
if HasNameOf.apply(self,db,child):
return True
return False

View File

@ -0,0 +1,54 @@
#
# 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: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules import HasGrampsId
#-------------------------------------------------------------------------
#
# HasNameOf
#
#-------------------------------------------------------------------------
class FatherHasIdOf(HasGrampsId):
"""Rule that checks for a person with a specific GRAMPS ID"""
labels = [ _('Person ID:') ]
name = _('Families with father with the <Id>')
description = _("Matches familis whose father has a specified "
"GRAMPS ID")
category = _('Father filters')
def apply(self,db,family):
father_handle = family.get_father_handle()
father = db.get_person_from_handle(father_handle)
return HasGrampsId.apply(self,db,father)

View File

@ -0,0 +1,53 @@
#
# 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: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules.Person import HasNameOf
#-------------------------------------------------------------------------
#
# HasNameOf
#
#-------------------------------------------------------------------------
class FatherHasNameOf(HasNameOf):
"""Rule that checks for full or partial name matches"""
name = _('Families with father with the <name>')
description = _("Matches familis whose father has a specified "
"(partial) name")
category = _('Father filters')
def apply(self,db,family):
father_handle = family.get_father_handle()
father = db.get_person_from_handle(father_handle)
return HasNameOf.apply(self,db,father)

View File

@ -0,0 +1,47 @@
#
# 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: _MatchesFilter.py 6932 2006-06-21 16:30:35Z dallingham $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase
#-------------------------------------------------------------------------
#
# MatchesFilter
#
#-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter"""
name = _('Families matching the <filter>')
description = _("Matches families macthed by the specified filter name")
namespace = 'Family'

View File

@ -0,0 +1,54 @@
#
# 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: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules import HasGrampsId
#-------------------------------------------------------------------------
#
# HasNameOf
#
#-------------------------------------------------------------------------
class MotherHasIdOf(HasGrampsId):
"""Rule that checks for a person with a specific GRAMPS ID"""
labels = [ _('Person ID:') ]
name = _('Families with mother with the <Id>')
description = _("Matches familis whose mother has a specified "
"GRAMPS ID")
category = _('Mother filters')
def apply(self,db,family):
mother_handle = family.get_mother_handle()
mother = db.get_person_from_handle(mother_handle)
return HasGrampsId.apply(self,db,mother)

View File

@ -0,0 +1,53 @@
#
# 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: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules.Person import HasNameOf
#-------------------------------------------------------------------------
#
# HasNameOf
#
#-------------------------------------------------------------------------
class MotherHasNameOf(HasNameOf):
"""Rule that checks for full or partial name matches"""
name = _('Families with mother with the <name>')
description = _("Matches familis whose mother has a specified "
"(partial) name")
category = _('Mother filters')
def apply(self,db,family):
mother_handle = family.get_mother_handle()
mother = db.get_person_from_handle(mother_handle)
return HasNameOf.apply(self,db,mother)

View File

@ -34,6 +34,13 @@ from _HasNoteRegexp import HasNoteRegexp
from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf
from _FamilyPrivate import FamilyPrivate from _FamilyPrivate import FamilyPrivate
from _HasEvent import HasEvent from _HasEvent import HasEvent
from _MatchesFilter import MatchesFilter
from _FatherHasNameOf import FatherHasNameOf
from _FatherHasIdOf import FatherHasIdOf
from _MotherHasNameOf import MotherHasNameOf
from _MotherHasIdOf import MotherHasIdOf
from _ChildHasNameOf import ChildHasNameOf
from _ChildHasIdOf import ChildHasIdOf
editor_rule_list = [ editor_rule_list = [
AllFamilies, AllFamilies,
@ -44,4 +51,11 @@ editor_rule_list = [
HasNoteMatchingSubstringOf, HasNoteMatchingSubstringOf,
FamilyPrivate, FamilyPrivate,
HasEvent, HasEvent,
MatchesFilter,
FatherHasNameOf,
FatherHasIdOf,
MotherHasNameOf,
MotherHasIdOf,
ChildHasNameOf,
ChildHasIdOf,
] ]

View File

@ -32,54 +32,16 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Filters from Filters.Rules._MatchesFilterBase import MatchesFilterBase
#from Filters import SystemFilters, CustomFilters
from Filters.Rules._Rule import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# MatchesFilter # MatchesFilter
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesFilter(Rule): class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter""" """Rule that checks against another filter"""
labels = [_('Filter name:')]
name = _('People matching the <filter>') name = _('People matching the <filter>')
description = _("Matches people macthed by the specified filter name") description = _("Matches people macthed by the specified filter name")
category = _('General filters') namespace = 'Person'
def prepare(self,db):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters('Person'):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.prepare(db)
if Filters.CustomFilters:
for filt in Filters.CustomFilters.get_filters('Person'):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.prepare(db)
def reset(self):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters('Person'):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.reset()
if Filters.CustomFilters:
for filt in Filters.CustomFilters.get_filters('Person'):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.reset()
def apply(self,db,person):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters('Person'):
if filt.get_name() == self.list[0]:
return filt.check(db,person.handle)
if Filters.CustomFilters:
for filt in Filters.CustomFilters.get_filters('Person'):
if filt.get_name() == self.list[0]:
return filt.check(db,person.handle)
return False

View File

@ -0,0 +1,89 @@
#
# 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: _MatchesFilter.py 6932 2006-06-21 16:30:35Z dallingham $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import Filters
from _Rule import Rule
#-------------------------------------------------------------------------
#
# MatchesFilter
#
#-------------------------------------------------------------------------
class MatchesFilterBase(Rule):
"""
Rule that checks against another filter.
This is a base rule for subclassing by specific objects.
Subclasses need to define the namespace class attribute.
"""
labels = [_('Filter name:')]
name = _('Objects matching the <filter>')
description = _("Matches objects macthed by the specified filter name")
category = _('General filters')
def prepare(self,db):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.prepare(db)
if Filters.CustomFilters:
for filt in Filters.CustomFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.prepare(db)
def reset(self):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.reset()
if Filters.CustomFilters:
for filt in Filters.CustomFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
for rule in filt.flist:
rule.reset()
def apply(self,db,obj):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
return filt.check(db,obj.handle)
if Filters.CustomFilters:
for filt in Filters.CustomFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
return filt.check(db,obj.handle)
return False

View File

@ -32,7 +32,7 @@ from xml.sax import handler
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _GenericFilter import GenericFilter from _GenericFilter import GenericFilterFactory
import Rules import Rules
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -62,7 +62,7 @@ class FilterParser(handler.ContentHandler):
else: else:
self.namespace = "generic" self.namespace = "generic"
elif tag == "filter": elif tag == "filter":
self.f = GenericFilter() self.f = GenericFilterFactory(self.namespace)()
self.f.set_name(attrs['name']) self.f.set_name(attrs['name'])
if attrs.has_key('function'): if attrs.has_key('function'):
try: try:

View File

@ -25,7 +25,6 @@ Package providing filtering framework for GRAMPS.
""" """
import RelLib import RelLib
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GenericFilter # GenericFilter
@ -210,3 +209,8 @@ class GenericFamilyFilter(GenericFilter):
return db.get_family_from_handle(handle) return db.get_family_from_handle(handle)
def GenericFilterFactory(namespace):
if namespace == 'Person':
return GenericFilter
elif namespace == 'Family':
return GenericFamilyFilter