6599: Add regular expression option to rules using the match_substring method
svn: r21933
This commit is contained in:
@@ -52,6 +52,7 @@ class HasCitation(Rule):
|
||||
name = _('Citations matching parameters')
|
||||
category = _('General filters')
|
||||
description = _("Matches citations with particular parameters")
|
||||
allow_regex = True
|
||||
|
||||
def prepare(self, db):
|
||||
self.date = None
|
||||
|
||||
@@ -52,6 +52,7 @@ class HasMedia(Rule):
|
||||
name = _('Media objects matching parameters')
|
||||
description = _("Matches media objects with particular parameters")
|
||||
category = _('General filters')
|
||||
allow_regex = True
|
||||
|
||||
def prepare(self,db):
|
||||
self.date = None
|
||||
|
||||
@@ -59,6 +59,7 @@ class HasPlace(Rule):
|
||||
name = _('Places matching parameters')
|
||||
description = _("Matches places with particular parameters")
|
||||
category = _('General filters')
|
||||
allow_regex = True
|
||||
|
||||
def apply(self, db, place):
|
||||
if not self.match_substring(0, place.get_title()):
|
||||
|
||||
@@ -52,6 +52,7 @@ class HasRepo(Rule):
|
||||
name = _('Repositories matching parameters')
|
||||
description = _("Matches Repositories with particular parameters")
|
||||
category = _('General filters')
|
||||
allow_regex = True
|
||||
|
||||
def prepare(self, dummy_db):
|
||||
if self.list[1]:
|
||||
|
||||
@@ -53,6 +53,7 @@ class HasCitationBase(Rule):
|
||||
name = _('Citations matching parameters')
|
||||
description = _("Matches citations with particular parameters")
|
||||
category = _('Citation/source filters')
|
||||
allow_regex = True
|
||||
|
||||
def prepare(self, db):
|
||||
self.date = None
|
||||
|
||||
@@ -54,6 +54,7 @@ class HasEventBase(Rule):
|
||||
name = _('Events matching parameters')
|
||||
description = _("Matches events with particular parameters")
|
||||
category = _('Event filters')
|
||||
allow_regex = True
|
||||
|
||||
def prepare(self, db):
|
||||
self.date = None
|
||||
|
||||
@@ -51,6 +51,7 @@ class HasSourceBase(Rule):
|
||||
name = _('Sources matching parameters')
|
||||
description = _("Matches sources with particular parameters")
|
||||
category = _('Citation/source filters')
|
||||
allow_regex = True
|
||||
|
||||
def apply(self,db,source):
|
||||
if not self.match_substring(0,source.get_title()):
|
||||
|
||||
@@ -53,6 +53,7 @@ class Rule(object):
|
||||
name = ''
|
||||
category = _('Miscellaneous filters')
|
||||
description = _('No description')
|
||||
allow_regex = False
|
||||
|
||||
def __init__(self, arg, use_regex=False):
|
||||
self.list = []
|
||||
|
||||
@@ -135,8 +135,8 @@ class FilterList(object):
|
||||
f.write(' comment="%s"' % self.fix(comment))
|
||||
f.write('>\n')
|
||||
for rule in the_filter.get_rules():
|
||||
f.write(' <rule class="%s">\n'
|
||||
% rule.__class__.__name__)
|
||||
f.write(' <rule class="%s" use_regex="%s">\n'
|
||||
% (rule.__class__.__name__, rule.use_regex))
|
||||
for value in rule.values():
|
||||
f.write(' <arg value="%s"/>\n' % self.fix(value))
|
||||
f.write(' </rule>\n')
|
||||
|
||||
@@ -52,6 +52,7 @@ class FilterParser(handler.ContentHandler):
|
||||
self.a = []
|
||||
self.cname = None
|
||||
self.namespace = 'Person'
|
||||
self.use_regex = False
|
||||
|
||||
def setDocumentLocator(self, locator):
|
||||
self.locator = locator
|
||||
@@ -82,6 +83,10 @@ class FilterParser(handler.ContentHandler):
|
||||
self.f.set_comment(attrs['comment'])
|
||||
self.gfilter_list.add(self.namespace, self.f)
|
||||
elif tag == "rule":
|
||||
if attrs.has_key('use_regex'):
|
||||
self.use_regex = attrs['use_regex'] == 'True'
|
||||
else:
|
||||
self.use_regex = False
|
||||
save_name = attrs['class']
|
||||
if save_name in old_names_2_class:
|
||||
self.r = old_names_2_class[save_name]
|
||||
@@ -115,7 +120,7 @@ class FilterParser(handler.ContentHandler):
|
||||
"Trying to load with subset of arguments.") %\
|
||||
self.f.get_name()
|
||||
nargs = len(self.r.labels)
|
||||
rule = self.r(self.a[0:nargs])
|
||||
rule = self.r(self.a[0:nargs], self.use_regex)
|
||||
self.f.add_rule(rule)
|
||||
else:
|
||||
if len(self.r.labels) > len(self.a):
|
||||
@@ -124,7 +129,7 @@ class FilterParser(handler.ContentHandler):
|
||||
"will be upgraded.") %\
|
||||
self.f.get_name()
|
||||
try:
|
||||
rule = self.r(self.a)
|
||||
rule = self.r(self.a, self.use_regex)
|
||||
except AssertionError, msg:
|
||||
print msg
|
||||
print _("ERROR: filter %s could not be correctly loaded. "
|
||||
|
||||
Reference in New Issue
Block a user