#2490 : Migration : register new arg values on custom_filter.xml
svn: r11857
This commit is contained in:
parent
f864a324ac
commit
0b59dad73b
@ -46,6 +46,14 @@ class HasNoteBase(Rule):
|
||||
description = _("Matches objects that have a certain number of notes")
|
||||
category = _('General filters')
|
||||
|
||||
def __init__(self, arg):
|
||||
# Upgrade from pre 3.1 HasNote filter, use defaults that correspond
|
||||
# Previous filter had 0 arguments
|
||||
if len(arg) == 0:
|
||||
Rule.__init__(self, ["0", 'greater than'])
|
||||
else:
|
||||
Rule.__init__(self, arg)
|
||||
|
||||
def prepare(self, db):
|
||||
# things we want to do just once, not for every handle
|
||||
if self.list[1] == _('lesser than'):
|
||||
|
@ -55,8 +55,9 @@ class Rule:
|
||||
def set_list(self, arg):
|
||||
assert isinstance(arg, list) or arg is None, "Argument is not a list"
|
||||
assert len(arg) == len(self.labels), \
|
||||
"Number of arguments does not match number of labels.\n"\
|
||||
"list: %s\nlabels: %s" % (arg,self.labels)
|
||||
"ERROR: Number of arguments does not match number of labels.\n"\
|
||||
" list: %s\n"\
|
||||
" labels: %s" % (arg,self.labels)
|
||||
self.list = arg
|
||||
|
||||
def values(self):
|
||||
|
@ -108,16 +108,26 @@ class FilterParser(handler.ContentHandler):
|
||||
def endElement(self, tag):
|
||||
if tag == "rule" and self.r is not None:
|
||||
if len(self.r.labels) < len(self.a):
|
||||
print "WARNING: Invalid number of arguments in filter '%s'!" %\
|
||||
print _("WARNING: To many arguments in filter '%s'!\n"\
|
||||
"Trying to load with subset of arguments.") %\
|
||||
self.f.get_name()
|
||||
nargs = len(self.r.labels)
|
||||
rule = self.r(self.a[0:nargs])
|
||||
self.f.add_rule(rule)
|
||||
elif len(self.r.labels) > len(self.a):
|
||||
print "ERROR: Invalid number of arguments in filter '%s'!" % \
|
||||
self.f.get_name()
|
||||
else:
|
||||
if len(self.r.labels) > len(self.a):
|
||||
print _("WARNING: To few arguments in filter '%s'!\n" \
|
||||
" Trying to load anyway in the hope this "\
|
||||
"will be upgraded.") %\
|
||||
self.f.get_name()
|
||||
try:
|
||||
rule = self.r(self.a)
|
||||
except AssertionError, msg:
|
||||
print msg
|
||||
print _("ERROR: filter %s could not be correctly loaded. "
|
||||
"Edit the filter!") % self.f.get_name()
|
||||
return
|
||||
|
||||
self.f.add_rule(rule)
|
||||
|
||||
def characters(self, data):
|
||||
|
Loading…
Reference in New Issue
Block a user