add new operator &: {key: 'id', operator: '&', value: ['a', 'b']

This commit is contained in:
j 2016-02-22 19:54:15 +05:30
parent c0ce0a556a
commit 5073fc1c52
2 changed files with 15 additions and 10 deletions

View file

@ -23,6 +23,7 @@ def get_operator(op, type='str'):
'<=': operators.le,
'^': operators.startswith_op,
'$': operators.endswith_op,
'&': operators.in_op,
},
'int': {
'==': operators.eq,
@ -113,11 +114,17 @@ class Parser(object):
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
elif k == 'id':
if op == '&':
ids = v
else:
ids = [v]
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
elif key_type in ("string", "text"):
if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower()
else:
v = v.lower()
q = get_operator(op)(self._find.findvalue, v)
if k != '*':
q &= (self._find.key == k)

View file

@ -29,14 +29,12 @@ oml.ui.statusbar = function() {
if (ui.listSelection.length) {
oml.api.find({
query: {
conditions: ui.listSelection.map(function(id) {
return {
conditions: [{
key: 'id',
operator: '==',
value: id
};
}),
operator: '|'
operator: '&',
value: ui.listSelection
}],
operator: '&'
}
}, function(result) {
that.set('selected', result.data);
@ -66,4 +64,4 @@ oml.ui.statusbar = function() {
return that;
};
};