From 3465d3ee9f28224488f267cb4098f0c286e0a1ea Mon Sep 17 00:00:00 2001 From: j Date: Thu, 18 Apr 2019 13:02:33 +0200 Subject: [PATCH] add & operator to find many ids --- pandora/document/managers.py | 6 +++++- pandora/oxdjango/managers.py | 3 +++ static/js/editDialog.js | 14 +++++++------- static/js/editDocumentsDialog.js | 14 +++++++------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pandora/document/managers.py b/pandora/document/managers.py index 5491aa1d..7c97b0f1 100644 --- a/pandora/document/managers.py +++ b/pandora/document/managers.py @@ -70,7 +70,11 @@ def buildCondition(k, op, v, user, exclude=False, owner=None): key_type = get_key_type(k) facet_keys = models.Document.facet_keys 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}) if exclude: q = ~Q(id__in=models.Document.objects.filter(q)) diff --git a/pandora/oxdjango/managers.py b/pandora/oxdjango/managers.py index c1a5edb7..560e2c55 100644 --- a/pandora/oxdjango/managers.py +++ b/pandora/oxdjango/managers.py @@ -10,6 +10,7 @@ def get_operator(op, type='str'): '<=': '__lte', '^': '__startswith', '$': '__endswith', + '&': '__in', }, 'istr': { '==': '__iexact', @@ -20,6 +21,7 @@ def get_operator(op, type='str'): '<=': '__lte', '^': '__istartswith', '$': '__iendswith', + '&': '__in', }, 'int': { '==': '', @@ -27,6 +29,7 @@ def get_operator(op, type='str'): '>=': '__gte', '<': '__lt', '<=': '__lte', + '&': '__in', } }[type].get(op, { 'str': '__contains', diff --git a/static/js/editDialog.js b/static/js/editDialog.js index 6ad47d02..f35747c0 100644 --- a/static/js/editDialog.js +++ b/static/js/editDialog.js @@ -78,14 +78,14 @@ pandora.ui.editDialog = function() { pandora.api.find({ keys: keys, query: { - conditions: ids.map(function(id) { - return { + conditions: [ + { key: 'id', - operator: '==', - value: id - }; - }), - operator: '|' + operator: '&', + value: ids + } + ], + operator: '&' } }, function(result) { var data = {}, diff --git a/static/js/editDocumentsDialog.js b/static/js/editDocumentsDialog.js index 2ae9e264..4d6b345f 100644 --- a/static/js/editDocumentsDialog.js +++ b/static/js/editDocumentsDialog.js @@ -77,14 +77,14 @@ pandora.ui.editDocumentsDialog = function() { pandora.api.findDocuments({ keys: keys, query: { - conditions: ids.map(function(id) { - return { + conditions: [ + { key: 'id', - operator: '==', - value: id - }; - }), - operator: '|' + operator: '&', + value: ids + } + ], + operator: '&' } }, function(result) { var data = {},