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

View File

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