From d7719962fda26bfc6576dd5b69ed9f78c9c1a852 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 14 May 2015 23:43:49 +0100 Subject: [PATCH] 8427: Add new IsEnclosedBy rule --- gramps/gen/filters/rules/place/__init__.py | 4 +- .../gen/filters/rules/place/_isenclosedby.py | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 gramps/gen/filters/rules/place/_isenclosedby.py diff --git a/gramps/gen/filters/rules/place/__init__.py b/gramps/gen/filters/rules/place/__init__.py index f769926a5..be2978157 100644 --- a/gramps/gen/filters/rules/place/__init__.py +++ b/gramps/gen/filters/rules/place/__init__.py @@ -40,6 +40,7 @@ from ._hasplace import HasPlace from ._hasdata import HasData from ._hasnolatorlon import HasNoLatOrLon from ._inlatlonneighborhood import InLatLonNeighborhood +from ._isenclosedby import IsEnclosedBy from ._matcheseventfilter import MatchesEventFilter from ._matchessourceconfidence import MatchesSourceConfidence from ._changedsince import ChangedSince @@ -66,5 +67,6 @@ editor_rule_list = [ MatchesEventFilter, ChangedSince, HasTag, - HasTitle + HasTitle, + IsEnclosedBy ] diff --git a/gramps/gen/filters/rules/place/_isenclosedby.py b/gramps/gen/filters/rules/place/_isenclosedby.py new file mode 100644 index 000000000..5fb8e6d9d --- /dev/null +++ b/gramps/gen/filters/rules/place/_isenclosedby.py @@ -0,0 +1,59 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2015 Nick Hall +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from ....const import GRAMPS_LOCALE as glocale +_ = glocale.translation.sgettext + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +from .. import Rule +from ....utils.location import located_in + +#------------------------------------------------------------------------- +# +# IsEnclosedBy +# +#------------------------------------------------------------------------- +class IsEnclosedBy(Rule): + """ + Rule that checks for a place enclosed by another place + """ + + labels = [_('ID:')] + name = _('Places enclosed by another place') + description = _('Matches a place enclosed by a particular place') + category = _('General filters') + + def prepare(self, db): + self.handle = db.get_place_from_gramps_id(self.list[0]).handle + + def apply(self, db, place): + if located_in(db, place.handle, self.handle): + return True + return False