From 9a4c24cdb41cbe47bdcab6b4648754f6d7b96712 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 26 Feb 2016 18:16:38 +0000 Subject: [PATCH] Support searching documents by entities --- pandora/document/managers.py | 7 ++++++- static/js/documentsPanel.js | 26 ++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pandora/document/managers.py b/pandora/document/managers.py index 0c50cbc7..2772d63c 100644 --- a/pandora/document/managers.py +++ b/pandora/document/managers.py @@ -5,6 +5,9 @@ from django.db.models import Q, Manager import ox from oxdjango.query import QuerySet +import entity.managers + + def parseCondition(condition, user, item=None): ''' ''' @@ -37,6 +40,9 @@ def buildCondition(k, op, v): return Q(**{k: v}) if isinstance(v, bool): #featured and public flag key = k + elif k == 'entity': + entity_key, v = entity.managers.namePredicate(op, v) + key = 'entities__' + entity_key else: key = "%s%s" % (k, { '==': '__iexact', @@ -124,4 +130,3 @@ class DocumentManager(Manager): qs = qs.filter(conditions) return qs - diff --git a/static/js/documentsPanel.js b/static/js/documentsPanel.js index b69ffa5d..fc779880 100644 --- a/static/js/documentsPanel.js +++ b/static/js/documentsPanel.js @@ -168,11 +168,13 @@ pandora.ui.documentsPanel = function(options) { $findSelect = Ox.Select({ items: isItemView ? [ {id: 'all', title: Ox._('Find: All')}, - {id: 'name', title: Ox._('Find: Name')} + {id: 'name', title: Ox._('Find: Name')}, + {id: 'entity', title: Ox._('Find: Entity')} ] : [ {id: 'all', title: Ox._('Find: All')}, {id: 'name', title: Ox._('Find: Name')}, - {id: 'user', title: Ox._('Find: User')} + {id: 'user', title: Ox._('Find: User')}, + {id: 'entity', title: Ox._('Find: Entity')} ], overlap: 'right', type: 'image' @@ -1009,27 +1011,19 @@ pandora.ui.documentsPanel = function(options) { ); } + var allKeys = ['user', 'name', 'entity', 'extension', 'description']; + function updateList() { var key = $findSelect.value(), value = $findInput.value(), itemCondition = isItemView ? {key: 'item', operator: '==', value: ui.item} : null, + findKeys = key == 'all' ? allKeys : [key], findQuery = { - conditions: [].concat( - key != 'user' - ? [{key: 'name', operator: '=', value: value}] - : [], - key == 'all' - ? [ - {key: 'extension', operator: '=', value: value}, - {key: 'description', operator: '=', value: value} - ] - : [], - key != 'name' - ? [{key: 'user', operator: '=', value: value}] - : [] - ), + conditions: findKeys.map(function(k) { + return {key: k, operator: '=', value: value}; + }), operator: '|' }, query = isItemView