From 4c28d1c74cb90d7d1d1a4a0f90ae9a970e55c5c6 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Mon, 27 Aug 2012 09:21:10 +0000 Subject: [PATCH] 6003: Not all sourcebase objects have the same source filters svn: r20270 --- po/POTFILES.in | 10 +++ src/Filters/Rules/Family/Makefile.am | 1 + src/Filters/Rules/Family/_HasCitation.py | 7 -- src/Filters/Rules/Family/_HasSourceOf.py | 49 ++++++++++++ src/Filters/Rules/Family/__init__.py | 2 + src/Filters/Rules/Makefile.am | 9 ++- src/Filters/Rules/MediaObject/Makefile.am | 4 + src/Filters/Rules/MediaObject/_HasCitation.py | 53 +++++++++++++ .../Rules/MediaObject/_HasSourceCount.py | 47 +++++++++++ src/Filters/Rules/MediaObject/_HasSourceOf.py | 49 ++++++++++++ .../MediaObject/_MatchesSourceConfidence.py | 46 +++++++++++ src/Filters/Rules/MediaObject/__init__.py | 8 ++ src/Filters/Rules/Person/_HasCitation.py | 7 -- src/Filters/Rules/Person/_HasSourceOf.py | 32 +------- src/Filters/Rules/Place/Makefile.am | 4 + src/Filters/Rules/Place/_HasCitation.py | 54 +++++++++++++ src/Filters/Rules/Place/_HasSourceCount.py | 47 +++++++++++ src/Filters/Rules/Place/_HasSourceOf.py | 49 ++++++++++++ .../Rules/Place/_MatchesSourceConfidence.py | 46 +++++++++++ src/Filters/Rules/Place/__init__.py | 8 ++ src/Filters/Rules/_HasCitationBase.py | 12 ++- src/Filters/Rules/_HasSourceOfBase.py | 77 +++++++++++++++++++ 22 files changed, 570 insertions(+), 51 deletions(-) create mode 100644 src/Filters/Rules/Family/_HasSourceOf.py create mode 100644 src/Filters/Rules/MediaObject/_HasCitation.py create mode 100644 src/Filters/Rules/MediaObject/_HasSourceCount.py create mode 100644 src/Filters/Rules/MediaObject/_HasSourceOf.py create mode 100644 src/Filters/Rules/MediaObject/_MatchesSourceConfidence.py create mode 100644 src/Filters/Rules/Place/_HasCitation.py create mode 100644 src/Filters/Rules/Place/_HasSourceCount.py create mode 100644 src/Filters/Rules/Place/_HasSourceOf.py create mode 100644 src/Filters/Rules/Place/_MatchesSourceConfidence.py create mode 100644 src/Filters/Rules/_HasSourceOfBase.py diff --git a/po/POTFILES.in b/po/POTFILES.in index ec923176e..ccfc94a48 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -454,6 +454,7 @@ src/Filters/Rules/_HasGrampsId.py src/Filters/Rules/_HasTextMatchingSubstringOf.py src/Filters/Rules/_IsPrivate.py src/Filters/Rules/_Rule.py +src/Filters/Rules/_HasSourceOfBase.py # Filters.Rules.Person package src/Filters/Rules/Person/_ChangedSince.py @@ -553,6 +554,7 @@ src/Filters/Rules/Family/_HasNoteRegexp.py src/Filters/Rules/Family/_HasReferenceCountOf.py src/Filters/Rules/Family/_HasRelType.py src/Filters/Rules/Family/_HasSourceCount.py +src/Filters/Rules/Family/_HasSourceOf.py src/Filters/Rules/Family/_HasTag.py src/Filters/Rules/Family/_IsBookmarked.py src/Filters/Rules/Family/_MatchesFilter.py @@ -604,6 +606,10 @@ src/Filters/Rules/Place/_MatchesFilter.py src/Filters/Rules/Place/_MatchesEventFilter.py src/Filters/Rules/Place/_PlacePrivate.py src/Filters/Rules/Place/_RegExpIdOf.py +src/Filters/Rules/Place/_HasSourceOf.py +src/Filters/Rules/Place/_MatchesSourceConfidence.py +src/Filters/Rules/Place/_HasSourceCount.py +src/Filters/Rules/Place/_HasCitation.py # Filters.Rules.Source package src/Filters/Rules/Source/_AllSources.py @@ -652,6 +658,10 @@ src/Filters/Rules/MediaObject/_HasTag.py src/Filters/Rules/MediaObject/_MatchesFilter.py src/Filters/Rules/MediaObject/_MediaPrivate.py src/Filters/Rules/MediaObject/_RegExpIdOf.py +src/Filters/Rules/MediaObject/_HasSourceCount.py +src/Filters/Rules/MediaObject/_HasCitation.py +src/Filters/Rules/MediaObject/_HasSourceOf.py +src/Filters/Rules/MediaObject/_MatchesSourceConfidence.py # Filters.Rules.Repository package src/Filters/Rules/Repository/_AllRepos.py diff --git a/src/Filters/Rules/Family/Makefile.am b/src/Filters/Rules/Family/Makefile.am index 10504f44c..cab7e56f2 100644 --- a/src/Filters/Rules/Family/Makefile.am +++ b/src/Filters/Rules/Family/Makefile.am @@ -19,6 +19,7 @@ pkgpython_PYTHON = \ _HasReferenceCountOf.py\ _HasRelType.py\ _HasSourceCount.py \ + _HasSourceOf.py \ _HasTag.py \ __init__.py\ _IsBookmarked.py\ diff --git a/src/Filters/Rules/Family/_HasCitation.py b/src/Filters/Rules/Family/_HasCitation.py index 79629c34c..f4e404d7c 100644 --- a/src/Filters/Rules/Family/_HasCitation.py +++ b/src/Filters/Rules/Family/_HasCitation.py @@ -52,10 +52,3 @@ class HasCitation(HasCitationBase): name = _('Family with the ') description = _("Matches families with a citation of a particular " "value") - - def apply(self, dbase, family): - for citation_handle in family.get_citation_list(): - citation = dbase.get_citation_from_handle(citation_handle) - if HasCitationBase.apply(self, dbase, citation): - return True - return False diff --git a/src/Filters/Rules/Family/_HasSourceOf.py b/src/Filters/Rules/Family/_HasSourceOf.py new file mode 100644 index 000000000..da9e0688a --- /dev/null +++ b/src/Filters/Rules/Family/_HasSourceOf.py @@ -0,0 +1,49 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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: _HasSourceOf.py 18548 2011-12-04 17:09:17Z kulath $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasSourceOfBase import HasSourceOfBase + +#------------------------------------------------------------------------- +# +# HasSourceOf +# +#------------------------------------------------------------------------- +class HasSourceOf(HasSourceOfBase): + """Rule that checks family that have a particular source.""" + + labels = [ _('Source ID:') ] + name = _('Families with the ') + category = _('Citation/source filters') + description = _('Matches families who have a particular source') diff --git a/src/Filters/Rules/Family/__init__.py b/src/Filters/Rules/Family/__init__.py index db9f0a1b3..1038dfee0 100644 --- a/src/Filters/Rules/Family/__init__.py +++ b/src/Filters/Rules/Family/__init__.py @@ -48,6 +48,7 @@ from _HasCitation import HasCitation from _FamilyPrivate import FamilyPrivate from _HasAttribute import HasAttribute from _HasEvent import HasEvent +from _HasSourceOf import HasSourceOf from _IsBookmarked import IsBookmarked from _MatchesFilter import MatchesFilter from _MatchesSourceConfidence import MatchesSourceConfidence @@ -72,6 +73,7 @@ editor_rule_list = [ HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, + HasSourceOf, HasCitation, FamilyPrivate, HasEvent, diff --git a/src/Filters/Rules/Makefile.am b/src/Filters/Rules/Makefile.am index aabe78529..5d8afdf51 100644 --- a/src/Filters/Rules/Makefile.am +++ b/src/Filters/Rules/Makefile.am @@ -19,6 +19,7 @@ pkgpython_PYTHON = \ _HasReferenceCountBase.py \ _HasSourceCountBase.py \ _HasSourceBase.py \ + _HasSourceOfBase.py \ _HasTagBase.py \ _HasTextMatchingRegexpOf.py\ _HasTextMatchingSubstringOf.py\ @@ -28,10 +29,10 @@ pkgpython_PYTHON = \ _RegExpIdBase.py\ _Rule.py\ _MatchesFilterBase.py\ - _MatchesEventFilterBase.py \ - _MatchesSourceConfidenceBase.py \ - _MatchesSourceFilterBase.py \ - _HasCitationBase.py + _MatchesEventFilterBase.py \ + _MatchesSourceConfidenceBase.py \ + _MatchesSourceFilterBase.py \ + _HasCitationBase.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules diff --git a/src/Filters/Rules/MediaObject/Makefile.am b/src/Filters/Rules/MediaObject/Makefile.am index 9f537172b..1cbeeb334 100644 --- a/src/Filters/Rules/MediaObject/Makefile.am +++ b/src/Filters/Rules/MediaObject/Makefile.am @@ -6,13 +6,17 @@ pkgpythondir = $(datadir)/@PACKAGE@/Filters/Rules/MediaObject pkgpython_PYTHON = \ _AllMedia.py\ _ChangedSince.py\ + _HasCitation.py \ _HasIdOf.py\ _HasMedia.py\ _HasNoteMatchingSubstringOf.py\ _HasNoteRegexp.py\ _HasReferenceCountOf.py\ + _HasSourceCount.py \ + _HasSourceOf.py \ _HasTag.py\ _MatchesFilter.py\ + _MatchesSourceConfidence.py \ _MediaPrivate.py\ _HasAttribute.py\ _RegExpIdOf.py\ diff --git a/src/Filters/Rules/MediaObject/_HasCitation.py b/src/Filters/Rules/MediaObject/_HasCitation.py new file mode 100644 index 000000000..80fbfe690 --- /dev/null +++ b/src/Filters/Rules/MediaObject/_HasCitation.py @@ -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: _HasCitation.py 18548 2011-12-04 17:09:17Z kulath $ + +""" +Filter rule to match persons with a particular citation. +""" +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasCitationBase import HasCitationBase + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasCitation(HasCitationBase): + """Rule that checks for a person with a particular value""" + + labels = [ _('Volume/Page:'), + _('Date:'), + _('Confidence level:')] + name = _('Media with the ') + description = _("Matches media with a citation of a particular " + "value") diff --git a/src/Filters/Rules/MediaObject/_HasSourceCount.py b/src/Filters/Rules/MediaObject/_HasSourceCount.py new file mode 100644 index 000000000..8465923d3 --- /dev/null +++ b/src/Filters/Rules/MediaObject/_HasSourceCount.py @@ -0,0 +1,47 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2008 Jerome Rapinat +# Copyright (C) 2008 Benny Malengier +# +# 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: _HasSourceCount.py 18548 2011-12-04 17:09:17Z kulath $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasSourceCountBase import HasSourceCountBase + +#------------------------------------------------------------------------- +# "People having sources" +#------------------------------------------------------------------------- +class HasSourceCount(HasSourceCountBase): + """Media with sources""" + + name = _('Media with sources') + description = _("Matches media with a certain number of sources connected to it") diff --git a/src/Filters/Rules/MediaObject/_HasSourceOf.py b/src/Filters/Rules/MediaObject/_HasSourceOf.py new file mode 100644 index 000000000..c728b1321 --- /dev/null +++ b/src/Filters/Rules/MediaObject/_HasSourceOf.py @@ -0,0 +1,49 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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: _HasSourceOf.py 18548 2011-12-04 17:09:17Z kulath $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasSourceOfBase import HasSourceOfBase + +#------------------------------------------------------------------------- +# +# HasSourceOf +# +#------------------------------------------------------------------------- +class HasSourceOf(HasSourceOfBase): + """Rule that checks media that have a particular source.""" + + labels = [ _('Source ID:') ] + name = _('Media with the ') + category = _('Citation/source filters') + description = _('Matches media who have a particular source') diff --git a/src/Filters/Rules/MediaObject/_MatchesSourceConfidence.py b/src/Filters/Rules/MediaObject/_MatchesSourceConfidence.py new file mode 100644 index 000000000..50960f74a --- /dev/null +++ b/src/Filters/Rules/MediaObject/_MatchesSourceConfidence.py @@ -0,0 +1,46 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2011 Jerome Rapinat +# +# 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 +# +# Filters/Rules/Person/_MatchesSourceConfidence.py +# $Id: _MatchesSourceConfidence.py 18361 2011-10-23 03:13:50Z paul-franklin $ +# + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import sgettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._MatchesSourceConfidenceBase import MatchesSourceConfidenceBase + +#------------------------------------------------------------------------- +# "Confidence level" +#------------------------------------------------------------------------- +class MatchesSourceConfidence(MatchesSourceConfidenceBase): + """Media matching a specific confidence level on its 'direct' source references""" + + labels = [_('Confidence level:')] + name = _('Media with at least one direct source >= ') + description = _("Matches media with at least one direct source with confidence level(s)") diff --git a/src/Filters/Rules/MediaObject/__init__.py b/src/Filters/Rules/MediaObject/__init__.py index 58c87d57e..f691721e4 100644 --- a/src/Filters/Rules/MediaObject/__init__.py +++ b/src/Filters/Rules/MediaObject/__init__.py @@ -27,11 +27,15 @@ Package providing filter rules for GRAMPS. from _AllMedia import AllMedia from _HasIdOf import HasIdOf from _RegExpIdOf import RegExpIdOf +from _HasCitation import HasCitation from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasReferenceCountOf import HasReferenceCountOf +from _HasSourceCount import HasSourceCount +from _HasSourceOf import HasSourceOf from _MediaPrivate import MediaPrivate from _MatchesFilter import MatchesFilter +from _MatchesSourceConfidence import MatchesSourceConfidence from _HasMedia import HasMedia from _HasAttribute import HasAttribute from _ChangedSince import ChangedSince @@ -41,11 +45,15 @@ editor_rule_list = [ AllMedia, HasIdOf, RegExpIdOf, + HasCitation, HasNoteRegexp, HasNoteMatchingSubstringOf, HasReferenceCountOf, + HasSourceCount, + HasSourceOf, MediaPrivate, MatchesFilter, + MatchesSourceConfidence, HasAttribute, ChangedSince, HasTag, diff --git a/src/Filters/Rules/Person/_HasCitation.py b/src/Filters/Rules/Person/_HasCitation.py index 558fe4cce..d22dd8049 100644 --- a/src/Filters/Rules/Person/_HasCitation.py +++ b/src/Filters/Rules/Person/_HasCitation.py @@ -51,10 +51,3 @@ class HasCitation(HasCitationBase): name = _('People with the ') description = _("Matches people with a citation of a particular " "value") - - def apply(self, dbase, person): - for citation_handle in person.get_citation_list(): - citation = dbase.get_citation_from_handle(citation_handle) - if HasCitationBase.apply(self, dbase, citation): - return True - return False diff --git a/src/Filters/Rules/Person/_HasSourceOf.py b/src/Filters/Rules/Person/_HasSourceOf.py index 2330f7570..808237c55 100644 --- a/src/Filters/Rules/Person/_HasSourceOf.py +++ b/src/Filters/Rules/Person/_HasSourceOf.py @@ -33,45 +33,17 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._Rule import Rule +from Filters.Rules._HasSourceOfBase import HasSourceOfBase #------------------------------------------------------------------------- # # HasSourceOf # #------------------------------------------------------------------------- -class HasSourceOf(Rule): +class HasSourceOf(HasSourceOfBase): """Rule that checks people that have a particular source.""" labels = [ _('Source ID:') ] name = _('People with the ') category = _('Citation/source filters') description = _('Matches people who have a particular source') - - def prepare(self,db): - if self.list[0] == '': - self.source_handle = None - self.nosource = True - return - - self.nosource = False - try: - self.source_handle = db.get_source_from_gramps_id( - self.list[0]).get_handle() - except: - self.source_handle = None - - def apply(self, db, person): - if not self.source_handle: - if self.nosource: - # check whether the citation list is empty as a proxy for - # there being no sources - return len(person.get_all_citation_lists()) == 0 - else: - return False - else: - for citation_handle in person.get_all_citation_lists(): - citation = db.get_citation_from_handle(citation_handle) - if citation.get_reference_handle() == self.source_handle: - return True - return False diff --git a/src/Filters/Rules/Place/Makefile.am b/src/Filters/Rules/Place/Makefile.am index 2d3a6e6b4..4646572b2 100644 --- a/src/Filters/Rules/Place/Makefile.am +++ b/src/Filters/Rules/Place/Makefile.am @@ -6,6 +6,7 @@ pkgpythondir = $(datadir)/@PACKAGE@/Filters/Rules/Place pkgpython_PYTHON = \ _AllPlaces.py\ _ChangedSince.py\ + _HasCitation.py \ _HasIdOf.py\ _HasNoLatOrLon.py\ _InLatLonNeighborhood.py\ @@ -15,8 +16,11 @@ pkgpython_PYTHON = \ _HasPlace.py\ _HasNote.py \ _HasReferenceCountOf.py\ + _HasSourceCount.py \ + _HasSourceOf.py \ _MatchesFilter.py\ _MatchesEventFilter.py\ + _MatchesSourceConfidence.py \ _PlacePrivate.py\ _RegExpIdOf.py\ __init__.py diff --git a/src/Filters/Rules/Place/_HasCitation.py b/src/Filters/Rules/Place/_HasCitation.py new file mode 100644 index 000000000..2636f0cdf --- /dev/null +++ b/src/Filters/Rules/Place/_HasCitation.py @@ -0,0 +1,54 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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: _HasCitation.py 18548 2011-12-04 17:09:17Z kulath $ + +""" +Filter rule to match family with a particular citation. +""" +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasCitationBase import HasCitationBase + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasCitation(HasCitationBase): + """Rule that checks for a family with a particular value""" + + labels = [ _('Volume/Page:'), + _('Date:'), + _('Confidence level:')] + name = _('Place with the ') + description = _("Matches places with a citation of a particular " + "value") diff --git a/src/Filters/Rules/Place/_HasSourceCount.py b/src/Filters/Rules/Place/_HasSourceCount.py new file mode 100644 index 000000000..8dcdd7057 --- /dev/null +++ b/src/Filters/Rules/Place/_HasSourceCount.py @@ -0,0 +1,47 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2008 Jerome Rapinat +# Copyright (C) 2008 Benny Malengier +# +# 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: _HasSourceCount.py 18548 2011-12-04 17:09:17Z kulath $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasSourceCountBase import HasSourceCountBase + +#------------------------------------------------------------------------- +# "People having sources" +#------------------------------------------------------------------------- +class HasSourceCount(HasSourceCountBase): + """Place with sources""" + + name = _('Place with sources') + description = _("Matches places with a certain number of sources connected to it") diff --git a/src/Filters/Rules/Place/_HasSourceOf.py b/src/Filters/Rules/Place/_HasSourceOf.py new file mode 100644 index 000000000..4482bff49 --- /dev/null +++ b/src/Filters/Rules/Place/_HasSourceOf.py @@ -0,0 +1,49 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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: _HasSourceOf.py 18548 2011-12-04 17:09:17Z kulath $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasSourceOfBase import HasSourceOfBase + +#------------------------------------------------------------------------- +# +# HasSourceOf +# +#------------------------------------------------------------------------- +class HasSourceOf(HasSourceOfBase): + """Rule that checks family that have a particular source.""" + + labels = [ _('Source ID:') ] + name = _('Places with the ') + category = _('Citation/source filters') + description = _('Matches places who have a particular source') diff --git a/src/Filters/Rules/Place/_MatchesSourceConfidence.py b/src/Filters/Rules/Place/_MatchesSourceConfidence.py new file mode 100644 index 000000000..5bb26380f --- /dev/null +++ b/src/Filters/Rules/Place/_MatchesSourceConfidence.py @@ -0,0 +1,46 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2011 Jerome Rapinat +# +# 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 +# +# Filters/Rules/Person/_MatchesSourceConfidence.py +# $Id: _MatchesSourceConfidence.py 18361 2011-10-23 03:13:50Z paul-franklin $ +# + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import sgettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._MatchesSourceConfidenceBase import MatchesSourceConfidenceBase + +#------------------------------------------------------------------------- +# "Confidence level" +#------------------------------------------------------------------------- +class MatchesSourceConfidence(MatchesSourceConfidenceBase): + """Media matching a specific confidence level on its 'direct' source references""" + + labels = [_('Confidence level:')] + name = _('Place with direct source >= ') + description = _("Matches places with at least one direct source with confidence level(s)") diff --git a/src/Filters/Rules/Place/__init__.py b/src/Filters/Rules/Place/__init__.py index d138b382c..5d0c343ef 100644 --- a/src/Filters/Rules/Place/__init__.py +++ b/src/Filters/Rules/Place/__init__.py @@ -29,12 +29,16 @@ from _AllPlaces import AllPlaces from _HasGallery import HasGallery from _HasIdOf import HasIdOf from _RegExpIdOf import RegExpIdOf +from _HasCitation import HasCitation +from _HasSourceOf import HasSourceOf +from _HasSourceCount import HasSourceCount from _HasNote import HasNote from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasReferenceCountOf import HasReferenceCountOf from _PlacePrivate import PlacePrivate from _MatchesFilter import MatchesFilter +from _MatchesSourceConfidence import MatchesSourceConfidence from _HasPlace import HasPlace from _HasNoLatOrLon import HasNoLatOrLon from _InLatLonNeighborhood import InLatLonNeighborhood @@ -46,12 +50,16 @@ editor_rule_list = [ HasGallery, HasIdOf, RegExpIdOf, + HasCitation, HasNote, HasNoteRegexp, HasNoteMatchingSubstringOf, HasReferenceCountOf, + HasSourceOf, + HasSourceCount, PlacePrivate, MatchesFilter, + MatchesSourceConfidence, HasPlace, HasNoLatOrLon, InLatLonNeighborhood, diff --git a/src/Filters/Rules/_HasCitationBase.py b/src/Filters/Rules/_HasCitationBase.py index 779984541..788d3c2ce 100644 --- a/src/Filters/Rules/_HasCitationBase.py +++ b/src/Filters/Rules/_HasCitationBase.py @@ -47,7 +47,6 @@ class HasCitationBase(Rule): First parameter is [Volume/page, Date, Confidence] """ - labels = [ _('Volume/Page:'), _('Date:'), _('Confidence:') ] @@ -63,8 +62,15 @@ class HasCitationBase(Rule): except: pass - def apply(self,db,citation): - if not self.match_substring(0,citation.get_page()): + def apply(self, dbase, object): + for citation_handle in object.get_citation_list(): + citation = dbase.get_citation_from_handle(citation_handle) + if self._apply(dbase, citation): + return True + return False + + def _apply(self, db, citation): + if not self.match_substring(0, citation.get_page()): return False if self.date: diff --git a/src/Filters/Rules/_HasSourceOfBase.py b/src/Filters/Rules/_HasSourceOfBase.py new file mode 100644 index 000000000..f27d4edd3 --- /dev/null +++ b/src/Filters/Rules/_HasSourceOfBase.py @@ -0,0 +1,77 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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: _HasSourceOf.py 18548 2011-12-04 17:09:17Z kulath $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._Rule import Rule + +#------------------------------------------------------------------------- +# +# HasSourceOf +# +#------------------------------------------------------------------------- +class HasSourceOfBase(Rule): + """Rule that checks for objects that have a particular source.""" + + labels = [ _('Source ID:') ] + name = _('Object with the ') + category = _('Citation/source filters') + description = _('Matches objects who have a particular source') + + def prepare(self,db): + if self.list[0] == '': + self.source_handle = None + self.nosource = True + return + + self.nosource = False + try: + self.source_handle = db.get_source_from_gramps_id( + self.list[0]).get_handle() + except: + self.source_handle = None + + def apply(self, db, object): + if not self.source_handle: + if self.nosource: + # check whether the citation list is empty as a proxy for + # there being no sources + return len(object.get_all_citation_lists()) == 0 + else: + return False + else: + for citation_handle in object.get_all_citation_lists(): + citation = db.get_citation_from_handle(citation_handle) + if citation.get_reference_handle() == self.source_handle: + return True + return False