add & operator to find many ids

This commit is contained in:
j 2019-04-18 13:02:33 +02:00
parent 4ec7e1b6c1
commit 3465d3ee9f
4 changed files with 22 additions and 15 deletions

View file

@ -70,7 +70,11 @@ def buildCondition(k, op, v, user, exclude=False, owner=None):
key_type = get_key_type(k) key_type = get_key_type(k)
facet_keys = models.Document.facet_keys facet_keys = models.Document.facet_keys
if k == 'id': if k == 'id':
v = ox.fromAZ(v) if op == '&' and isinstance(v, list):
v = [ox.fromAZ(id_) for id_ in v]
k += get_operator(op)
else:
v = ox.fromAZ(v)
q = Q(**{k: v}) q = Q(**{k: v})
if exclude: if exclude:
q = ~Q(id__in=models.Document.objects.filter(q)) q = ~Q(id__in=models.Document.objects.filter(q))

View file

@ -10,6 +10,7 @@ def get_operator(op, type='str'):
'<=': '__lte', '<=': '__lte',
'^': '__startswith', '^': '__startswith',
'$': '__endswith', '$': '__endswith',
'&': '__in',
}, },
'istr': { 'istr': {
'==': '__iexact', '==': '__iexact',
@ -20,6 +21,7 @@ def get_operator(op, type='str'):
'<=': '__lte', '<=': '__lte',
'^': '__istartswith', '^': '__istartswith',
'$': '__iendswith', '$': '__iendswith',
'&': '__in',
}, },
'int': { 'int': {
'==': '', '==': '',
@ -27,6 +29,7 @@ def get_operator(op, type='str'):
'>=': '__gte', '>=': '__gte',
'<': '__lt', '<': '__lt',
'<=': '__lte', '<=': '__lte',
'&': '__in',
} }
}[type].get(op, { }[type].get(op, {
'str': '__contains', 'str': '__contains',

View file

@ -78,14 +78,14 @@ pandora.ui.editDialog = function() {
pandora.api.find({ pandora.api.find({
keys: keys, keys: keys,
query: { query: {
conditions: ids.map(function(id) { conditions: [
return { {
key: 'id', key: 'id',
operator: '==', operator: '&',
value: id value: ids
}; }
}), ],
operator: '|' operator: '&'
} }
}, function(result) { }, function(result) {
var data = {}, var data = {},

View file

@ -77,14 +77,14 @@ pandora.ui.editDocumentsDialog = function() {
pandora.api.findDocuments({ pandora.api.findDocuments({
keys: keys, keys: keys,
query: { query: {
conditions: ids.map(function(id) { conditions: [
return { {
key: 'id', key: 'id',
operator: '==', operator: '&',
value: id value: ids
}; }
}), ],
operator: '|' operator: '&'
} }
}, function(result) { }, function(result) {
var data = {}, var data = {},