3 def match_dict(self, dic, filter):
4 # We suppose if a field is in filter, it is therefore in the dic
8 for k, v in filter.items():
9 if k[0] in Filter.modifiers:
12 elif k in ['-SORT', '-LIMIT', '-OFFSET']:
18 if isinstance(v, list):
19 match &= (dic[k] in v) # array ?
21 match &= (dic[k] == v)
23 if isinstance(v, list):
24 match &= (dic[k] not in v) # array ?
26 match &= (dic[k] != v) # array ?
28 if isinstance(v, StringTypes):
30 match &= dic[k].startswith('%s.' % v)
34 if isinstance(v, StringTypes):
35 match &= dic[k] == v or dic[k].startswith('%s.' % v)
37 match &= (dic[k] <= v)
39 if isinstance(v, StringTypes):
41 match &= v.startswith('%s.' % dic[k])
45 if isinstance(v, StringTypes):
47 match &= dic[k] == v or v.startswith('%s.' % dic[k])
49 match &= (dic[k] >= v)
51 match &= (dic[k] & v) # array ?
53 match &= (dic[k] | v) # array ?
55 match &= (v in dic[k])
58 def project_select_and_rename_fields(self, table, pkey, filters, fields):
62 if self.selection or self.match_dict(row, filters):
68 for k,v in row.items():
69 # if no fields = keep everything
70 if not fields or k in fields or k == pkey:
75 def get_objects(self, method, filters=None, fields=None):
76 if not method in ['authorities', 'resources', 'users', 'slices']:
77 raise Exception, "Unknown object type"
78 results = self.get(method, filters, fields)
79 # Perform missing operations
80 if results and (filter and not self.selection) or (fields and not self.projection):
81 results = self.project_select_and_rename_fields(results, 'id', filters, fields)