fix filters for name search

svn: r16016
This commit is contained in:
Benny Malengier 2010-10-20 19:22:40 +00:00
parent 7b66d246b8
commit 7400976c96
4 changed files with 66 additions and 28 deletions

View File

@ -34,6 +34,7 @@ from gen.ggettext import sgettext as _
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
from gen.lib import NameOriginType
#-------------------------------------------------------------------------
#
@ -43,41 +44,76 @@ from Filters.Rules._Rule import Rule
class HasNameOf(Rule):
"""Rule that checks for full or partial name matches"""
labels = [ _('Given name:'),
_('Family name:'),
_('Suffix:'),
labels = [ _('Given name:'),
_('Full Family name:'),
_('person|Title:'),
_('Suffix:'),
_('Call Name:'),
_('Nick Name:'),
_('Prefix:'),
_('Single Surname:'),
_('Connector'),
_('Patronymic:'),
_('Call Name:'),]
_('Family Nick Name:')]
name = _('People with the <name>')
description = _("Matches people with a specified (partial) name")
category = _('General filters')
def apply(self,db,person):
self.firstn = self.list[0]
self.lastn = self.list[1]
self.surn = self.list[2]
self.title = self.list[3]
self.prefix = self.list[4]
self.patr = self.list[5]
self.calln = self.list[6]
def prepare(self, db):
self.firstn = self.list[0].upper()
self.lastn = self.list[1].upper()
self.title = self.list[2].upper()
self.suffix = self.list[3].upper()
self.calln = self.list[4].upper()
self.nick = self.list[5].upper()
self.famnick = self.list[10].upper()
#surname parts
self.prefix = self.list[6].upper()
self.surn = self.list[7].upper()
self.con = self.list[8].upper()
self.patr = self.list[9].upper()
def apply(self, db, person):
for name in [person.get_primary_name()] + person.get_alternate_names():
val = 1
if self.firstn and name.get_first_name().upper().find(self.firstn.upper()) == -1:
valpref = 0
if not self.prefix:
valpref = 1
valsurn = 0
if not self.surn:
valsurn = 1
valcon = 0
if not self.con:
valcon = 1
valpatr = 0
if not self.patr:
valpatr = 1
if self.firstn and name.get_first_name().upper().find(self.firstn) == -1:
val = 0
if self.lastn and name.get_surname().upper().find(self.lastn.upper()) == -1:
elif self.lastn and name.get_surname().upper().find(self.lastn) == -1:
val = 0
if self.surn and name.get_suffix().upper().find(self.surn.upper()) == -1:
elif self.suffix and name.get_suffix().upper().find(self.surn) == -1:
val = 0
if self.title and name.get_title().upper().find(self.title.upper()) == -1:
elif self.title and name.get_title().upper().find(self.title) == -1:
val = 0
if self.prefix and name.get_prefix().upper().find(self.prefix.upper()) == -1:
elif self.calln and name.get_call_name().upper().find(self.calln) == -1:
val = 0
if self.patr and name.get_patronymic().upper().find(self.patr.upper()) == -1:
elif self.nick and name.get_nick_name().upper().find(self.nick) == -1:
val = 0
if self.calln and name.get_call_name().upper().find(self.calln.upper()) == -1:
elif self.famnick and name.get_family_nick_name().upper().find(self.famnick) == -1:
val = 0
if val == 1:
else:
#obtain surnames
for surn in name.get_surname_list():
if self.prefix and surn.get_prefix().upper().find(self.prefix) != -1:
valpref = 1
if self.surn and surn.get_surname().upper().find(self.surn) != -1:
valsurn = 1
if self.con and surn.get_connector().upper().find(self.con) != -1:
valcon = 1
if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \
and surn.get_surname().upper().find(self.patr) != -1:
valpatr = 1
if val == 1 and valpref == 1 and valsurn == 1 and valcon == 1 and valpatr ==1:
return True
return False

View File

@ -48,8 +48,9 @@ class IncompleteNames(Rule):
def apply(self,db,person):
for name in [person.get_primary_name()] + person.get_alternate_names():
if name.get_first_name() == "":
return True
if name.get_surname() == "":
if name.get_first_name().strip() == "":
return True
for surn in name.get_surname_list():
if surn.get_surname().strip() == "":
return True
return False

View File

@ -59,8 +59,8 @@ class RegExpName(Rule):
def apply(self,db,person):
for name in [person.get_primary_name()] + person.get_alternate_names():
for field in [name.first_name, name.surname, name.suffix, name.title,
name.prefix, name.patronymic, name.call]:
for field in [name.first_name, name.get_surname(), name.suffix,
name.title, name.nick, name.famnick, self.call]:
if self.match.match(field):
return True
else:

View File

@ -49,12 +49,13 @@ class SearchName(Rule):
category = _('General filters')
def apply(self, db, person):
src = self.list[0].upper()
if not src:
return False
for name in [person.get_primary_name()] + person.get_alternate_names():
for field in [name.first_name, name.surname, name.suffix, name.title,
name.prefix, name.patronymic, name.call]:
for field in [name.first_name, name.get_surname(), name.suffix,
name.title, name.nick, name.famnick, self.call]:
if src and field.upper().find(src) != -1:
return True
else: