Support searching documents by entities

This commit is contained in:
Will Thompson 2016-02-26 18:16:38 +00:00
parent 738a9282b4
commit 9a4c24cdb4
2 changed files with 16 additions and 17 deletions

View file

@ -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

View file

@ -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