class FilterKeyDoesNotExis Exception pass class FilterUnknownBinding E

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class FilterKeyDoesNotExist(Exception):
pass
class FilterUnknownBinding(Exception):
pass
class Filter(object):
def __init__(self, conditions):
self.conditions = conditions
def __parse_conditions(self, x):
binding = unicode(x['binding'], 'utf8')
operator = unicode(x['op'], 'utf8')
key = getattr(TChartAttributes, x['fieldId'].lower(), None)
value = unicode(x['value'], 'utf8')
if key is None:
raise FilterKeyDoesNotExist(u"Field doesn't exist.")
if binding == 'and':
binding_callback = and_
elif binding == 'or':
binding_callback = or_
else:
raise FilterUnknownBinding(u'Unknown binding detected.')
if operator == '=':
return binding_callback(key == value)
else:
return bindind_callback(key != value)
def get_filters(self):
filters = []
for x in self.conditions:
filters.append(self.__parse_conditions(x))
return filters