forked from 0x2620/pandora
Support searching documents by entities
This commit is contained in:
parent
738a9282b4
commit
9a4c24cdb4
2 changed files with 16 additions and 17 deletions
|
@ -5,6 +5,9 @@ from django.db.models import Q, Manager
|
||||||
import ox
|
import ox
|
||||||
from oxdjango.query import QuerySet
|
from oxdjango.query import QuerySet
|
||||||
|
|
||||||
|
import entity.managers
|
||||||
|
|
||||||
|
|
||||||
def parseCondition(condition, user, item=None):
|
def parseCondition(condition, user, item=None):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
@ -37,6 +40,9 @@ def buildCondition(k, op, v):
|
||||||
return Q(**{k: v})
|
return Q(**{k: v})
|
||||||
if isinstance(v, bool): #featured and public flag
|
if isinstance(v, bool): #featured and public flag
|
||||||
key = k
|
key = k
|
||||||
|
elif k == 'entity':
|
||||||
|
entity_key, v = entity.managers.namePredicate(op, v)
|
||||||
|
key = 'entities__' + entity_key
|
||||||
else:
|
else:
|
||||||
key = "%s%s" % (k, {
|
key = "%s%s" % (k, {
|
||||||
'==': '__iexact',
|
'==': '__iexact',
|
||||||
|
@ -124,4 +130,3 @@ class DocumentManager(Manager):
|
||||||
qs = qs.filter(conditions)
|
qs = qs.filter(conditions)
|
||||||
|
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
|
@ -168,11 +168,13 @@ pandora.ui.documentsPanel = function(options) {
|
||||||
$findSelect = Ox.Select({
|
$findSelect = Ox.Select({
|
||||||
items: isItemView ? [
|
items: isItemView ? [
|
||||||
{id: 'all', title: Ox._('Find: All')},
|
{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: 'all', title: Ox._('Find: All')},
|
||||||
{id: 'name', title: Ox._('Find: Name')},
|
{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',
|
overlap: 'right',
|
||||||
type: 'image'
|
type: 'image'
|
||||||
|
@ -1009,27 +1011,19 @@ pandora.ui.documentsPanel = function(options) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var allKeys = ['user', 'name', 'entity', 'extension', 'description'];
|
||||||
|
|
||||||
function updateList() {
|
function updateList() {
|
||||||
var key = $findSelect.value(),
|
var key = $findSelect.value(),
|
||||||
value = $findInput.value(),
|
value = $findInput.value(),
|
||||||
itemCondition = isItemView
|
itemCondition = isItemView
|
||||||
? {key: 'item', operator: '==', value: ui.item}
|
? {key: 'item', operator: '==', value: ui.item}
|
||||||
: null,
|
: null,
|
||||||
|
findKeys = key == 'all' ? allKeys : [key],
|
||||||
findQuery = {
|
findQuery = {
|
||||||
conditions: [].concat(
|
conditions: findKeys.map(function(k) {
|
||||||
key != 'user'
|
return {key: k, operator: '=', value: value};
|
||||||
? [{key: 'name', operator: '=', value: value}]
|
}),
|
||||||
: [],
|
|
||||||
key == 'all'
|
|
||||||
? [
|
|
||||||
{key: 'extension', operator: '=', value: value},
|
|
||||||
{key: 'description', operator: '=', value: value}
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
key != 'name'
|
|
||||||
? [{key: 'user', operator: '=', value: value}]
|
|
||||||
: []
|
|
||||||
),
|
|
||||||
operator: '|'
|
operator: '|'
|
||||||
},
|
},
|
||||||
query = isItemView
|
query = isItemView
|
||||||
|
|
Loading…
Reference in a new issue