8427: Add new IsEnclosedBy rule

This commit is contained in:
Nick Hall 2015-05-14 23:43:49 +01:00
parent 2b90e90987
commit d7719962fd
2 changed files with 62 additions and 1 deletions

View File

@ -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
]

View File

@ -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