6599: Add regex parameter to rules which override the constructor

svn: r21941
This commit is contained in:
Nick Hall 2013-04-10 13:21:14 +00:00
parent fc0c0f474e
commit 71040c0fd1
14 changed files with 26 additions and 34 deletions

View File

@ -50,8 +50,8 @@ class HasData(Rule):
description = _("Matches events with data of a particular value") description = _("Matches events with data of a particular value")
category = _('General filters') category = _('General filters')
def __init__(self, list): def __init__(self, list, use_regex=False):
Rule.__init__(self, list) Rule.__init__(self, list, use_regex)
self.event_type = self.list[0] self.event_type = self.list[0]
self.date = self.list[1] self.date = self.list[1]

View File

@ -47,8 +47,8 @@ class MatchesRegexpOf(Rule):
"which matches a regular expression") "which matches a regular expression")
category = _('General filters') category = _('General filters')
def __init__(self, list): def __init__(self, list, use_regex=False):
Rule.__init__(self, list) Rule.__init__(self, list, use_regex)
try: try:
self.match = re.compile(list[0], re.I|re.U|re.L) self.match = re.compile(list[0], re.I|re.U|re.L)

View File

@ -49,8 +49,8 @@ class HasBirth(Rule):
description = _("Matches people with birth data of a particular value") description = _("Matches people with birth data of a particular value")
category = _('Event filters') category = _('Event filters')
def __init__(self,list): def __init__(self, list, use_regex=False):
Rule.__init__(self,list) Rule.__init__(self, list, use_regex)
if self.list[0]: if self.list[0]:
self.date = DateHandler.parser.parse(self.list[0]) self.date = DateHandler.parser.parse(self.list[0])
else: else:

View File

@ -51,8 +51,8 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith):
"with anybody matched by a filter") "with anybody matched by a filter")
category = _("Ancestral filters") category = _("Ancestral filters")
def __init__(self, list): def __init__(self, list, use_regex=False):
HasCommonAncestorWith.__init__(self, list) HasCommonAncestorWith.__init__(self, list, use_regex)
self.ancestor_cache = {} self.ancestor_cache = {}
def prepare(self, db): def prepare(self, db):

View File

@ -49,8 +49,8 @@ class HasDeath(Rule):
description = _("Matches people with death data of a particular value") description = _("Matches people with death data of a particular value")
category = _('Event filters') category = _('Event filters')
def __init__(self,list): def __init__(self, list, use_regex=False):
Rule.__init__(self,list) Rule.__init__(self, list, use_regex)
if self.list[0]: if self.list[0]:
self.date = DateHandler.parser.parse(self.list[0]) self.date = DateHandler.parser.parse(self.list[0])
else: else:

View File

@ -43,10 +43,10 @@ class HavePhotos(HasGalleryBase):
name = _('People with <count> media') name = _('People with <count> media')
description = _("Matches people with a certain number of items in the gallery") description = _("Matches people with a certain number of items in the gallery")
def __init__(self, arg): def __init__(self, arg, use_regex=False):
# Upgrade from pre 3.1 HasPhotos filter, use defaults that correspond # Upgrade from pre 3.1 HasPhotos filter, use defaults that correspond
# Previous filter had 0 arguments # Previous filter had 0 arguments
if len(arg) == 0: if len(arg) == 0:
HasGalleryBase.__init__(self, ["0", 'greater than']) HasGalleryBase.__init__(self, ["0", 'greater than'], use_regex)
else: else:
HasGalleryBase.__init__(self, arg) HasGalleryBase.__init__(self, arg, use_regex)

View File

@ -41,8 +41,8 @@ class HasTextMatchingRegexpOf(HasTextMatchingSubstringOf):
parameter. parameter.
""" """
def __init__(self,list): def __init__(self, list, use_regex=False):
HasTextMatchingSubstringOf.__init__(self,list) HasTextMatchingSubstringOf.__init__(self, list, use_regex)
def prepare(self,db): def prepare(self,db):
self.db = db self.db = db

View File

@ -50,10 +50,6 @@ class IsAncestorOfFilterMatch(IsAncestorOf):
description = _("Matches people that are ancestors " description = _("Matches people that are ancestors "
"of anybody matched by a filter") "of anybody matched by a filter")
def __init__(self,list):
IsAncestorOf.__init__(self,list)
def prepare(self,db): def prepare(self,db):
self.db = db self.db = db
self.map = set() self.map = set()

View File

@ -50,10 +50,6 @@ class IsDescendantOfFilterMatch(IsDescendantOf):
description = _("Matches people that are descendants " description = _("Matches people that are descendants "
"of anybody matched by a filter") "of anybody matched by a filter")
# def __init__(self,list):
# IsDescendantOf.__init__(self,list)
def prepare(self,db): def prepare(self,db):
self.db = db self.db = db
self.map = set() self.map = set()

View File

@ -49,8 +49,8 @@ class RegExpName(Rule):
description = _("Matches people's names with a specified regular expression") description = _("Matches people's names with a specified regular expression")
category = _('General filters') category = _('General filters')
def __init__(self, list): def __init__(self, list, use_regex=False):
Rule.__init__(self, list) Rule.__init__(self, list, use_regex)
try: try:
self.match = re.compile(list[0],re.I|re.U|re.L) self.match = re.compile(list[0],re.I|re.U|re.L)

View File

@ -49,13 +49,13 @@ class HasNoteBase(Rule):
description = _("Matches objects that have a certain number of notes") description = _("Matches objects that have a certain number of notes")
category = _('General filters') category = _('General filters')
def __init__(self, arg): def __init__(self, arg, use_regex=False):
# Upgrade from pre 3.1 HasNote filter, use defaults that correspond # Upgrade from pre 3.1 HasNote filter, use defaults that correspond
# Previous filter had 0 arguments # Previous filter had 0 arguments
if len(arg) == 0: if len(arg) == 0:
Rule.__init__(self, ["0", 'greater than']) Rule.__init__(self, ["0", 'greater than'], use_regex)
else: else:
Rule.__init__(self, arg) Rule.__init__(self, arg, use_regex)
def prepare(self, db): def prepare(self, db):
# things we want to do just once, not for every handle # things we want to do just once, not for every handle

View File

@ -47,8 +47,8 @@ class HasNoteRegexBase(Rule):
"matching a regular expression") "matching a regular expression")
category = _('General filters') category = _('General filters')
def __init__(self, list): def __init__(self, list, use_regex=False):
Rule.__init__(self, list) Rule.__init__(self, list, use_regex)
try: try:
self.match = re.compile(list[0],re.I|re.U|re.L) self.match = re.compile(list[0],re.I|re.U|re.L)

View File

@ -40,8 +40,8 @@ class HasTextMatchingRegexpOf(HasTextMatchingSubstringOf):
""" """
Wrap HasTextMatchingSubstringOf to enable the regex_match parameter. Wrap HasTextMatchingSubstringOf to enable the regex_match parameter.
""" """
def __init__(self, list): def __init__(self, list, use_regex=False):
HasTextMatchingSubstringOf.__init__(self, list) HasTextMatchingSubstringOf.__init__(self, list, use_regex)
# FIXME: This needs to be written for an arbitrary object # FIXME: This needs to be written for an arbitrary object
# if possible # if possible

View File

@ -51,8 +51,8 @@ class RegExpIdBase(Rule):
"the regular expression") "the regular expression")
category = _('General filters') category = _('General filters')
def __init__(self, list): def __init__(self, list, use_regex=False):
Rule.__init__(self, list) Rule.__init__(self, list, use_regex)
try: try:
self.match = re.compile(list[0], re.I|re.U|re.L) self.match = re.compile(list[0], re.I|re.U|re.L)