related to 4336: added regex to name filter
svn: r16223
This commit is contained in:
parent
739da49fb8
commit
af803ad785
@ -27,6 +27,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.ggettext import sgettext as _
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -54,7 +55,8 @@ class HasNameOf(Rule):
|
||||
_('Single Surname:'),
|
||||
_('Connector'),
|
||||
_('Patronymic:'),
|
||||
_('Family Nick Name:')]
|
||||
_('Family Nick Name:'),
|
||||
_('Regular-Expression matching:')]
|
||||
name = _('People with the <name>')
|
||||
description = _("Matches people with a specified (partial) name")
|
||||
category = _('General filters')
|
||||
@ -72,6 +74,10 @@ class HasNameOf(Rule):
|
||||
self.surn = self.list[7].upper()
|
||||
self.con = self.list[8].upper()
|
||||
self.patr = self.list[9].upper()
|
||||
if len(self.list) >= 12:
|
||||
self.regular_expression = bool(int(self.list[11]))
|
||||
else:
|
||||
self.regular_expression = False
|
||||
|
||||
def apply(self, db, person):
|
||||
for name in [person.get_primary_name()] + person.get_alternate_names():
|
||||
@ -88,32 +94,60 @@ class HasNameOf(Rule):
|
||||
valpatr = 0
|
||||
if not self.patr:
|
||||
valpatr = 1
|
||||
if self.firstn and name.get_first_name().upper().find(self.firstn) == -1:
|
||||
val = 0
|
||||
elif self.lastn and name.get_surname().upper().find(self.lastn) == -1:
|
||||
val = 0
|
||||
elif self.suffix and name.get_suffix().upper().find(self.surn) == -1:
|
||||
val = 0
|
||||
elif self.title and name.get_title().upper().find(self.title) == -1:
|
||||
val = 0
|
||||
elif self.calln and name.get_call_name().upper().find(self.calln) == -1:
|
||||
val = 0
|
||||
elif self.nick and name.get_nick_name().upper().find(self.nick) == -1:
|
||||
val = 0
|
||||
elif self.famnick and name.get_family_nick_name().upper().find(self.famnick) == -1:
|
||||
val = 0
|
||||
if self.regular_expression:
|
||||
if self.firstn and not re.match(self.firstn, name.get_first_name(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
elif self.lastn and not re.match(self.lastn, name.get_surname(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
elif self.suffix and not re.match(self.suffix, name.get_suffix(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
elif self.title and not re.match(self.title, name.get_title(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
elif self.calln and not re.match(self.calln, name.get_call_name(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
elif self.nick and not re.match(self.nick, name.get_nick_name(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
elif self.famnick and not re.match(self.famnick, name.get_family_nick_name(), re.I|re.U|re.L):
|
||||
val = 0
|
||||
else:
|
||||
#obtain surnames
|
||||
for surn in name.get_surname_list():
|
||||
if self.prefix and re.match(self.prefix, surn.get_prefix(), re.I|re.U|re.L):
|
||||
valpref = 1
|
||||
if self.surn and re.match(self.surn, surn.get_surname(), re.I|re.U|re.L):
|
||||
valsurn = 1
|
||||
if self.con and re.match(self.con, surn.get_connector(), re.I|re.U|re.L):
|
||||
valcon = 1
|
||||
if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \
|
||||
and re.match(self.patr, surn.get_surname(), re.I|re.U|re.L):
|
||||
valpatr = 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 self.firstn and name.get_first_name().upper().find(self.firstn) == -1:
|
||||
val = 0
|
||||
elif self.lastn and name.get_surname().upper().find(self.lastn) == -1:
|
||||
val = 0
|
||||
elif self.suffix and name.get_suffix().upper().find(self.surn) == -1:
|
||||
val = 0
|
||||
elif self.title and name.get_title().upper().find(self.title) == -1:
|
||||
val = 0
|
||||
elif self.calln and name.get_call_name().upper().find(self.calln) == -1:
|
||||
val = 0
|
||||
elif self.nick and name.get_nick_name().upper().find(self.nick) == -1:
|
||||
val = 0
|
||||
elif self.famnick and name.get_family_nick_name().upper().find(self.famnick) == -1:
|
||||
val = 0
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user