Test the id and the fullid in condition

And use obj.to_dict instead of dict(obj.iter_fields())
This commit is contained in:
Florent 2014-04-09 10:30:19 +02:00
commit 7555938470

View file

@ -92,22 +92,29 @@ class ResultsCondition(IResultsCondition):
self.condition_str = condition_str self.condition_str = condition_str
def is_valid(self, obj): def is_valid(self, obj):
d = dict(obj.iter_fields()) d = obj.to_dict()
# We evaluate all member of a list at each iteration. # We evaluate all member of a list at each iteration.
for _or in self.condition: for _or in self.condition:
myeval = True myeval = True
for condition in _or: for condition in _or:
if condition.left in d: if condition.left in d:
# We have to change the type of v, always gived as string by application # in the case of id, test id@backend and id
typed = type(d[condition.left]) if condition.left == 'id':
try: tocompare = condition.right
if isinstance(d[condition.left], date_utils.date): evalfullid = functions[condition.op](tocompare, d['id'])
tocompare = date(*[int(x) for x in condition.right.split('-')]) evalid = functions[condition.op](tocompare, obj.id)
else: myeval = evalfullid or evalid
tocompare = typed(condition.right) else:
myeval = functions[condition.op](tocompare, d[condition.left]) # We have to change the type of v, always gived as string by application
except: typed = type(d[condition.left])
myeval = False try:
if isinstance(d[condition.left], date_utils.date):
tocompare = date(*[int(x) for x in condition.right.split('-')])
else:
tocompare = typed(condition.right)
myeval = functions[condition.op](tocompare, d[condition.left])
except:
myeval = False
else: else:
raise ResultsConditionError(u'Field "%s" is not valid.' % condition.left) raise ResultsConditionError(u'Field "%s" is not valid.' % condition.left)
# Do not try all AND conditions if one is false # Do not try all AND conditions if one is false